EE337 Lab 2
EE337 Lab 2
1. [5 points] Write an assembly program to add two 16-bit numbers. Use the following
program as a starting point. Add your code in the ADD16 subroutine.
ADD16:
// ADD YOUR CODE HERE
RET
END
• The first number x is stored at locations 70H and 71H, with its most significant
byte (MSB) in 70H and the least significant byte in 71H.
• The second number y is similarly stored at locations 72H (MSB) and 73H (LSB).
• Since the result z = x + y can be 17 bits long, store the result in memory
locations 74H, 75H, 76H.
• For z = z16 z15 z14 . . . z3 z2 z1 z0 where z0 is the least significant bit (LSB) and
z16 is the most significant bit (MSB), the memory location 74H should have
0000000z16 , the memory location 75H should have the bits z15 z14 . . . z8 , and the
memory location 76H should have the bits z7 z6 . . . z0 .
TA Checkpoint 1
Check the following two cases:
• x = 1234H, y = DCBAH.
• x = FFFFH, y = FFFFH.
2. [5 points] Write an assembly program to swap the contents of two memory locations
using XOR operation. Use the following program as a starting point. Add your codes
in the XOR SWAP subroutine.
Refer to XOR Swap Algorithm to understand how to perform the given task.
XORSWAP:
// ADD YOUR CODE HERE
RET
END
• The inputs a and b are stored at locations 60H and 61H respectively.
• After the swap operation, location 60H must contain the value of b and location
61H must contain the value of a.
TA Checkpoint 2
Check the following two cases:
• a = 56H, b = 12H.
• a = 34H, b = E1H.
3. [10 points] Write an assembly program to find the largest of 8 given numbers. Use
the following program as a starting point. Add your codes in the MAX subroutine.
Refer to Largest Element in Array to understand how to perform the given task.
MAX:
// ADD YOUR CODE HERE
RET
END
TA Checkpoint 3
Check the following 2 cases:
• Inputs numbers = 14H, 69H, 26H, 5BH, 7FH, 1AH, 00H, C5H.
• Inputs numbers = D4H, CCH, C1H, AFH, 92H, D4H, 16H, 01H.