Programming Exercise I (4 points): (Implementing DigitValue2ASCIT) The objective
ID: 3752668 • Letter: P
Question
Programming Exercise I (4 points): (Implementing DigitValue2ASCIT) The objective of this exercise is to write the procedure DigitValue2ASCII that converts a value v of a hexadecimal digit d into the ASClI code of the digit d. The procedure DigitValue2ASCII uses the register AL as parameter. We assume that AL contains a value between 0 and OFh-(15)o. Therefore, AL will contain the value of a hexadecimal digit '0, to F. You do not have to test AL for the range. The procedure DigitValue2ASCII must return in the register DL the ASCll code of the digit d Examples: I) If AL contains the value 4, procedure DigitValue2ASCII returns in DL the ASCII code of '4', i.e. DL -34h 2) If AL contains the value 0Ch-(12) o, your procedure return in DL the ASClI code of 'C', i.e. DL43hExplanation / Answer
DigitValue2ASCII:
push rbp
mov rbp, rsp
sub rsp, 32
mov eax, edi
mov BYTE PTR [rbp-20], al
movzx eax, BYTE PTR [rbp-20]
shr al, 4
mov BYTE PTR [rbp-1], al
add BYTE PTR [rbp-1], 48
cmp BYTE PTR [rbp-1], 57
jbe .L2
add BYTE PTR [rbp-1], 7
.L2:
movzx eax, BYTE PTR [rbp-1]
mov edi, eax
mov eax, 0
call uart_tx
movzx eax, BYTE PTR [rbp-20]
and eax, 15
mov BYTE PTR [rbp-1], al
add BYTE PTR [rbp-1], 48
cmp BYTE PTR [rbp-1], 57
jbe .L3
add BYTE PTR [rbp-1], 7
.L3:
movzx eax, BYTE PTR [rbp-1]
mov edi, eax
mov eax, 0
call uart_tx
nop
leave
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.