I really need help please leave comments if you can In this lab, you will be con
ID: 1846795 • Letter: I
Question
I really need help please leave comments if you can
Explanation / Answer
From the ascii table, the acceptable values will be from 0x30 to 0x39(0 to 9) and 0x41 to 0x46(A to F) ( boundaries inclusive)
AREA Program,CODE,READONLY
ENTRY
Main:
LDR R0,=asciiCode ; load the address of the string in r0
LDR R1,=BINARY_FORM ; load the address to store the result
EOR R2,R2,R2 ; clear contents of r2
EOR R4,R4,R4 ; clear contents of r4
Loop:
LDRB R3,[R0] ; Load character from string
ADD R0,R0,#4 ; Increment the pointer to the string
CMP R3,#0 ; check for end of string
BEQ Done ; end is found, jump to infinite loop
CMP R3,#0X2F ; compare with 0x2f
BLE Loop ; Less than 0x30, out of bounds
CMP R3,#0x3A ; compare with 0x3A
BGE Loop1 ; greater than 0x39, out of bounds , brach to check for A-F
SUB R4,R3,#0X30 ; subtract the ascii value by 0x30 to read the binary value, store it in r4
Found:
ADD R2,R2,R4 ; store the value in r2
MOV R2,R2,LSL #8 ; rotate r2 8 bits ie 1 byte
ADD R4,R4,#1 ; increment counter to check if 4 bytes are found
CMP R4,#4
BLT Loop ; 4bytes not completed, loop back for next character
EOR R4,R4,R4 ; clear r4(count) as 4 bytes are completed
STR R2,[R1] ; store the result in memory
ADD R1,R1,#4 ; increment the result pointer
EOR R2,R2,R2 ; clear contents of r2
BAL Loop ; loop back for next character
Loop1:
CMP R3,#0X40 ; compare with 0x40
BLE Loop ; value less than 0x40, out of bounds
CMP R3,#0X47 ; compare with 0x47
BGE Loop ; value greater than 0x47, out of bounds
SUB R4,R3,#0X40 ; subtract the value by 40 and 9 to get the exact binary value
ADD R4,R4,9
BAL Found
Done:
BAL Done ; infinite loop, end of program
AREA asciiCode,DATA
ASCII_STRING DCB "49b132",0
BINARY_FORM SPACE 20
END
Please reply any further clarification is needed :)