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

contains an unsigned value which is supposed to be between 0 and 15. souldprint

ID: 3724049 • Letter: C

Question

contains an unsigned value which is supposed to be between 0 and 15. souldprint the value in AL as a hex digit ASCll character. Assume one byte reserved at Hexchar to hold the character. Cmp al, jIs it in 8-9 range? NoteTos9 It is 0-9 ; set upper half of register to 3h ('0"=30h) NoteTo9: cmp al, Is it in A-F range? NotAToF It is A-F Set upper half of register to 4h ; Add 1 to register ("A 41h) ; Save character in HexChar PrintDig: mov Specify syswrite call Specify file descriptor 1: syswrite mov eax,4 mov ebx,1 mov ecx, Hexchar Specify byte to write mov edx, 1 ; specify size = 1 ; Make kernel call to write digit It's not printable, value > eFh NotAToF:

Explanation / Answer

cmp al,09h ;comparing the al with 09h
ja Not0To9 ; if al > 09h then the number is not in range of 0-9
;if in 0-9
add al,30h; add 30h to all as the ascii value of 0 is 30h
;if the al contains the 8 if we add 30h to al now al contains the 38 which is ascii value of "8"
jmp printDig;jump to print function
Not0To9:;if entered value greater than 09h
cmp al,15h;comparing the al with 15;
ja NotAToF;if al is greaer than 15 then then it was not a hexadecimal number
add al,30h;;else add 30h to make the upper half 4h as the al already contains the 10h or above in it
;if al contains the 11h then if we add the 30h to it then the total value in it was 41h so we set upper half to 4h
add al,01h;add 01h to al as the ascii range of alphabets starts at 41h
printDig:
mov [HexChar],al;saving the character to HexChar
mov eax, 4
mov ebx, 1
mov ecx, HexChar
mov edx, 1
int 0x80;kernal call to write digit
NotAToF:

note:

if you have any doubt please comment