Write a program called UNPACK to convert the 16bit BCD varia
Write a program called UNPACK to convert the 16-bit BCD variable in memory locations 0x40001000 and 0x40001001 to four ASCII characters with the high-order digit first, beginning in memory location 40001004H.
use the Keil assembler discussed in class and use the program shell from Assembly2.s as a starting point for each program.
AREA Assembly1, CODE, READONLY
EXPORT __main
__main
ENTRY
mystart LDR r3,= 0x40001000 ;point to RAM location
;
;************************************************************************
; For other programs (projects) replace the code below with new code.
; Leave the code outside the ******* lines as is for all programs.
; begin initialize data
LDR r4,= 0x25 ;set first operand = 0x100
LDR r5,= 0x50 ;set second operand to 0x50
STRB r4,[r3,#0] ;write first operand to memory
STRB r5,[r3,#1] ;write second operqand to memory
; end initialize data
LDRB r0,[r3,#0] ;get first operand
LDRB r1,[r3,#1] ;get second operand
ADD r2,r0,r1 ;form the sum of the two values
STRB r2,[r3,#2] ;save sum
; STRB r2,[r3,#3] ;save sum
;************************************************************************
;
; an infinite loop because the processor continues to fetch instructions
stop BAL stop
END ;END directive to show nothing more in file
Solution
1. Write a program called UNPACK to convert the 16-bit BCD variable in memory locations 0x40001000 and 0x40001001 to four ASCII characters with the high-order digit first, beginning in memory location 40001004H.
(0x40001000H) = 58
Result = (0x40001001) = 08 and
(40001004H) = 05
Source program
LDA 0x40001000H: Get the packed BCD number
ANI FOH : Mask lower nibble
RRC
RRC
RRC
RRC : Adjust higher BCD digit as a lower digit
STA 0x40001001: Store the partial result
LDA 40001004H: .Get the original BCD number
ANI OFH : Mask higher nibble
STA 40001004H: Store the result
HLT : Terminate program execution
