Make your own free website on Tripod.com

HexLoc   MachWord Label     Source Code       Comments

00000000 00000000            .org 1000H
00001000 80000000  A:        .dc 80000000H    ;Most negative 32 bit number
00001004 ffffffff  B:        .dc -1           ;Minus 1
00001008 00000000  SUM:      .dw 1            ;Make room for sum
0000100c 00000000  Overflow: .dc 0            ;No Overflow
00001010 00000000            .org 5000H
00005000 2a80503c            la r10, Finish   ;Finished routine
00005004 2ac05030            la r11, Minus    ;A is negative
00005008 2901ffff            la r4, -1        ;Used if overflow occurs
0000500c 107fbff0            ldr r1, A        ;Put A in r1
00005010 10bfbff0            ldr r2, B        ;Put B in r2
00005014 60c22000            add r3, r1, r2   ;Sum goes to r3
00005018 20ffbfec            str r3, SUM      ;Store SUM
0000501c 40161005            brmi r11, r1     ;A is negative
00005020 40142005            brmi r10, r2     ;B is negative -- No Overflow
00005024 40143004            brpl r10, r3     ;Sum is also positive --
                                              ;No overflow
00005028 213fbfe0            str r4, Overflow ;Set Overflow indicator
0000502c 40140001            br r10           ;Finished with
                                              ;positive numbers
00005030 40142004  Minus:    brpl r10, r2     ;B is plus -- No overflow
00005034 40143005            brmi r10, r3     ;Sum is also negative --
                                              ;no overflow
00005038 213fbfd0            str r4, Overflow ;Set Overflow indicator
0000503c f8000000  Finish:   stop

This program repeats the action taken to indicate overflow for both negative and positive numbers. It gives greatest flexibility in cases where different actions must be taken for positive and negative numbers -- for example if the overflow indicator were set at +1 for positive numbers and -1 for negative numbers. Contrast this with the program shown after the picture of the simulator window.

HexLoc    MachWord  Label         Source Code         Comments
00000000  00000000                .org 1000H
00001000  80000000  A:            .dc 80000000H     ;Most negative 32 bit
                                                    ;number
00001004  ffffffff  B:            .dc -1            ;Minus 1
00001008  00000000  SUM:          .dw 1
0000100c  00000000  Indicator:    .dc 0
00001010  00000000                .org 5000H
00005000  2a80503c                la r10, Finish    ;Finished routine
00005004  2ac05030                la r11, Minus     ;A is negative
00005008  2b005038                la r12, Overflow  ;Address of overflow routine
0000500c  2901ffff                la r4, -1         ;Used if overflow occurs
00005010  107fbfec                ldr r1, A
00005014  10bfbfec                ldr r2, B
00005018  60c22000                add r3, r1, r2
0000501c  20ffbfe8                str r3, SUM       ;Store SUM
00005020  40161005                brmi r11, r1      ;A is negative
00005024  40142005                brmi r10, r2      ;B is negative --
                                                    ;No Overflow
00005028  40183005                brmi r12, r3      ;Sum is also negative --
                                                    ;Overflow
0000502c  40140001                br r10            ;Finished with positive
                                                    ;numbers
00005030  40142004  Minus:        brpl r10, r2      ;B is plus --
                                                    ;No overflow
00005034  40143005                brmi r10, r3      ;Sum is also negative --
                                                    ;no overflow
00005038  213fbfd0  Overflow:     str r4, Indicator ;Set overflow indicator
0000503c  f8000000  Finish:       stop

This program uses a single routine to indicate overflow for both positive and negative numbers and is more efficient when the overflow routine is long.  In this case both programs are equally efficient and require 16 instructions plus assembler directives.