I need to do this task:
Write the program in 8051 assembler which copies the memory range 30H – 3FH to the memory range 40H – 4FH, copying the odd values without a change and the even values converted to the BCD format. Do not use any subroutines.
Right now I have a program that saves the odd values but skips the even values:
MOV R0,#30H
MOV R1,#40H
LOOP:
MOV A,@R0
ANL A,#00000001B
JZ NOT_INTERESTED
MOV A,@R0
MOV @R1,A
INC R1
NOT_INTERESTED:
INC R0
CJNE R0,#40H,LOOP
and I have a program that converts values to BCD:
MOV 30H,#63
MOV A,30H
CALL HEX_2_BCD
MOV 31H,A
HEX_2_BCD:
MOV B,#10
DIV AB
SWAP A
ADD A,B
RET
Do you know how I can combine them to get the needed result?
The code that converts to BCD is wrong. Upon returning from
CALL HEX_2_BCD, theAregister holds the BCD. Fine, but then the code needlessly falls through in the conversion code. This is not very exemplary. Nonetheless, you can extract from it the essential instructions that perform the BCD conversion:Because in the new program every byte from the source range will have to be written to the destination range, it will be easiest if we conditionally jump for the bytes that have an odd values and that can be written unmodified.
Furthermore, if we modify the test for even/odd a bit, we wouldn't have to reload the
Aregister. Remember theAregister is a Special Function Register whose bits are bit addressable using bit addresses 0E0h to 0E7h.It's probably a good idea to verify if the number that you want to convert to BCD is less than 100, else the converted result will be kinda worthless!