Name: Spyros Blanas
Section: 1
Here is the assembly file that generated the code shown above.
Here is the assembly file that generated the code shown above.
Here is the assembly file that generated the code shown above.
I would use the PC-Relative addressing mode because of its simplicity and because the distance falls within the limits of this mode.
The Base+offset addressing mode has no restrictions on how far away the data are stored. I would first use operate-type instructions to load the appropriate value into a base register, and then load from that register (base) with an offset of 0.
I would use the method described above for contiguously stored values. I would use the LEA (immediate addressing mode) instruction to make a register point at the start of the contiguous segment, and then use Base+offset to load specific values.
When we add two numbers, overflow can occur only if they have the same sign. Similarly in the case of subtraction, overflow can occur only when they have different signs. If we are comparing a positive and a negative number then the postive one is always greater, without considering the magnitude of the numbers. We can use these facts to get around the overflow problem. The sample code explains how you can do it.
ADD R3, R3, #0 BRn R3ISNEGATIVE ;R3 is positive ADD R4, R4, #0 BRp COMPARE ;R3 is postive, R4 is negative BR COPYR3TOR1 R3ISNEGATIVE: ;R3 is negative ADD R4, R4, #0 BRn COMPARE ;R3 is negative, R4 is positive BR COPYR4TOR1 COMPARE: ;both of same sign, so compare NOT R5, R4 ADD R5, R5, #1 ADD R5, R5, R3 BRn COPYR4TOR1 COPYR3TOR1: ADD R1, R3, #0 BR END COPYR4TOR1: ADD R1, R4, #0 END