LAB1 Using Subroutines and Macros (Part 1, 2, and 3) Overview The purpose of thi
ID: 3789246 • Letter: L
Question
LAB1 Using Subroutines and Macros (Part 1, 2, and 3) Overview The purpose of this lab is to program the MC8051 to add multi bytes two signed integers. To simplify our laboratory, we will assume three bytes long (24 bits) signed integers. Each of the three bytes will be defined in three consecutive code memory bytes using the "DB" assembler directive. The program will store the answer in three consecutive data memory bytes starting at Ram address 40H. The program will also display the answer on P0, P1, and P2 staring with the LS Byte in PO. Port 3 pin 0 (P3.0) will be set if an overflow takes place, otherwise it will stay cleared. Three versions of the program will be implemented starting with all code included in one main program. The second implementation will employ two subroutines to make advantage of the repeated code blocks. The final implementation will utilize two Macross to reduce the size of the source program and improve its readability. Steps First, configure your code and data memory. The MAIN:" program starts at code memory location 30H The first integer uses code memory locations 100H, 101H, and 102H in the Intel 1 little endian format. The second integer uses code memory locations 105H, 106H, and 107H Second, configure parallel port 0, port 1, port 2, and P3.0 for output Write and debug the code to add the two integers and store the answer in data memory locations 40H, 41H, and 42H. Update PO, P1, and P2 to display the same addition result. Flag an overflow condition on P3.1 by setting it Third, rewrite the program utilizing subroutines to make u repeated code blocks. Define the created. Subroutines after the main program before the program "END" directive. Fourth, rewrite the program utilizing Macros to make use of theExplanation / Answer
Here the first integer uses code memory location 100H, 101H and 102H, let the value will be held in R1,R2 and R3. R1 for lower bytes, R3 for the higher bytes.
Similarly, the second integer uses 105H, 106H and 107H. Let the lower 8bits will stored in R4 and next 8bits in R5 and upper byte in R6.
Now first of all the data at address location should moved to respective registers,
main:
MOV R1,[100] ; move value at address 100 to R1
MOV R2,[101] ; move value at address 101 to R2
MOV R3,[102] ; move value at address 102 to R3
MOV R4,[105] ; move value at address 105 to R4
MOV R5,[106] ; move value at address 106 to R5
MOV R6,[107] ; move value at address 107 to R6
;Now, Step 1:Add lower bytes R1 and R4 and leave the answer in P0
mov A,R1 ;move lower byte to the accumulator
add A,R4 ;add second lower byte to the accumulator
mov R7,A ;move answer to the lower byte of result
;Step 2:Add next bytes R2 and R5 and leave the answer in P1 and add carry from step 1
mov A,R2 ;move next byte to the accumulator
add A,R5 ;add second 8 bits to the accumulator
mov P1,A ;move answer to the next 8 bits of result
;Step 3:Add next bytes R3 and R6 and leave the answer in P2 and add carry from step 2
mov A,R3 ;move high byte to the accumulator
add A,R6 ;add second high bytes to the accumulator
mov P2,A ;move answer to the high bytes of result
step 4: Put any carry from step 3 in final R9
To perform two multi bytes integer upto 16 bytes
steps involved in this are:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.