Question: Computer science Custom subroutine example # 4 section . bss temp resb 1 ; used by atoi _ 2 res resb 2 ; used by

Computer science
Custom subroutine example #4
section .bss
temp resb 1 ; used by atoi_2
res resb 2; used by itoa_2
val resb 1
section .text
global _start
_start:
mov eax, '28' ; place input into eax register
call atoi_2; call the subroutine
mov [val], eax; place return value into "val"
mov eax, [val]
call print_itoa2
call exit
atoi_2:
xor ecx, ecx ; zero out reg.
mov ecx, eax ; Transfer to a register not being used
xor eax, eax ; Zero out the eax reg.
mov al, cl ; place 1st character into 8-bit register
sub al,'0' ; remove ASCII offset to reveal integer digit
mov bx,10; place 10 into bx for future multiplication
mul bx ; ax = ax * bx (recall that al is lowest 8-bits of ax so they hold the same value in this case)
mov [temp], ax ; store total (so far) into temp
xor eax, eax; zero out reg.
mov al, ch ; place 2nd character into 8-bit register
sub al,'0'; remove ASCII offset again...
add eax, [temp]; add the temp. reg. value
ret ; return to caller
print_itoa2:
mov bx,10
div bx
add ax,'0'
mov [res], byte ax
add dx,'0'
mov [res+1], byte dx
xor eax, eax
xor edx, edx
mov ecx, res
mov edx, 2
call print
ret
print:
mov eax, 4
mov ebx, 1
int 0x80
ret
exit:
mov eax, 1
mov ebx, 0
int 0x80
Computer science Custom subroutine example # 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!