lve the following problemss a. Write a code that will add three BCD numbers each
ID: 3598148 • Letter: L
Question
lve the following problemss a. Write a code that will add three BCD numbers each of size 3 digits. b. Write a program that will read 10 numbers from location 30H in RAM, find the sum, and store it in location 60H in RAM. Find also the maximum number of the 10-numbers stored in RAM and store it at B register. Write a code to solve the following problem: Suppose I have two switches connected as follow: Switch 1 is connected to port 3, pin 5. Switch 2 is connected to port 3, pin 7. A light bulb is connected to port 1, pin 1. When you turn any switch on, the light bulb should be on; otherwise the light bulb should be off. c.Explanation / Answer
(2) Here in this EdSim code the 10 value are stored in RAM from starting location of 30H. We use a register R2 to store the counts. To calculate the max value, we put the first value in R1, then we compare the remaining values with R1 and if some value is greater than R1, then put that value in R1, just like the concept in C.
int X[10],
int MAX=X[0];
for(i=1 ; i < 10 ; i++)
{
if(X[i] > MAX)
MAX=X[i];
}
START
MOV R0, #30H ; load pointer
MOV R2, #10 ; load counter
CLR A ; A=0
MOV R7, A ; clear R7
MOV R1, A ; store byte pointer to R1 in order to find max
AGAIN:
ADD A,@R0 ; add the byte pointer to A by R0
JNC NEXT ; if CY=0 don’t accumulate carry
INC R7 ; keep track of carries
NEXT:
INC R0 ; increment pointer
CJNE @R0, R1, OVER ; compare RAM data with value in accumulator
OVER:
JNC J1 ; @Ro > R1
DJNZ R2, AGAIN ; repeat until R2 becomes zero
MOV #60, A ; store sum at 60H location
MOV B,R1 ; store maximum value in B register
J1:
MOV R1, @Ro ; store greater value in R1
DJNZ R2, AGAIN ; repeat until R2 becomes zero
MOV #60, A ; store sum at 60H location
MOV B,R1 ; store maximum value in B register
END
(1) Here DA (Decimal Adjust) instruction must be used after the addition of BCD numbers. We can only use DA with A, and it can be used only after addition instruction, so in this example
MOV A, #4H ; load accumulator with first BCD operand 4H
MOV R0, #5H ; load accumulator with second BCD operand 5H
MOV R1, #6H ; load accumulator with third BCD operand 6H
ADD A, R0 ; add the value in A with R0 and store result in A
DA A ; Decimal adjust for BCD addition
ADD A, R1 ; add the value in A with R1 and store result in A
DA A ; Decimal adjust for BCD addition
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.