Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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


In this lab, you will be converting an ASCII string found in memory into its binary equivalent. If the ASCII string contains values that do not correspond to hex "0' through 'F', they should be skipped over. For example, if the string is "42s3t9", 0x04020309 should be stored in memory as the final result. If the string is "OFFaB", OxOOOFOFOB should be stored in memory as the final result. Your program should load the first byte of the ASCII code (corresponding to the first character in the string) into a register for analysis and store the binary equivalent in memory if it is valid. When analysis is complete, the program should load the next byte from memory. The ASCII string will be null terminated, and the program should end when it is reached. (Hint: use the simple relationship between the ASCII code and the hex equivalent to your advantage - you will find many ASCII tables with the hex equivalent of characters online.) You will read the characters from the address at ASCII STRING and store the final result in memory at the address of BINARY FORM. You will receive full credit for this part by showing your program produces the correct final string for the test string in the "code given" above, as well as several test strings given to you by the lab instructor during lab time. 30 points will be given for lab report, which should meet all general lab report formatting requirements discussed in class.

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 :)