Question: Please help me with this assembly code. So in this code I need to print my eax. but in the debugger it always say segmentation
Please help me with this assembly code. So in this code I need to print my eax. but in the debugger it always say segmentation fault. And my prof says in line my mov $edx is right, but i also need to move dx to a memory location, then move the mem loc to ecx. so what memory location should i use?.
data
equ STDIN,
equ STDOUT,
equ READ,
equ WRITE,
equ EXIT,
equ SUCCESS,
text
global start
#subroutine to print a number
printnumber:
xor ecx, ecx #counter for the number of digits
calculatedigits:
movl $edx #clear before division
movl $ebx
div ebx #eaxebx quotient in eax, remainer in edx
add $dl #convert digit to ASCII
push dx #push ASCII digit into stacks
inc ecx #increment counter
cmp $eax #check if quotient is zero
jne calculatedigits #if eax is not zero, continue calculation
printdigits:
movl ecx, ebx #save counter value
printloop:
pop dx #pop digit from stack
mov dlal #move digit to al for printing
movl $edx #length of
movl $STDOUT, ebx #file descriptor
movl $WRITE, eax #system calL
int $x #call kernel
dec ecx #decrement counter
jmp printloop #if counter is not zero, print next digit
ret #return from the subroutine
start:
#test
movl $eax #put the nuber to be printed
call printnumber #call the subroutine
#test
movl $eax #put the number to be printed
call printnumber #call the subroutine
done:
movl $EXIT, eax
movl $SUCCESS, ebx
int $x
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
