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 28 my mov $1,%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, 0
.equ STDOUT, 1
.equ READ, 3
.equ WRITE, 4
.equ EXIT, 1
.equ SUCCESS, 0
.text
.global _start
#subroutine to print a number
print_number:
xor %ecx, %ecx #counter for the number of digits
calculate_digits:
movl $0,%edx #clear before division
movl $10,%ebx
div %ebx #eax/ebx, quotient in eax, remainer in edx
add $'0',%dl #convert digit to ASCII
push %dx #push ASCII digit into stacks
inc %ecx #increment counter
cmp $0,%eax #check if quotient is zero
jne calculate_digits #if eax is not zero, continue calculation
print_digits:
movl %ecx, %ebx #save counter value
print_loop:
pop %dx #pop digit from stack
mov %dl,%al #move digit to al for printing
movl $1,%edx #length of 1
movl $STDOUT, %ebx #file descriptor
movl $WRITE, %eax #system calL
int $0x80 #call kernel
dec %ecx #decrement counter
jmp print_loop #if counter is not zero, print next digit
ret #return from the subroutine
_start:
#test1
movl $12345,%eax #put the nuber to be printed
call print_number #call the subroutine
#test2
movl $67890,%eax #put the number to be printed
call print_number #call the subroutine
done:
movl $EXIT, %eax
movl $SUCCESS, %ebx
int $0x80

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!