Question: learning AT&T x86 assembly language. write an assembly program which takes an integer n, then print itdigit by digit. FIND THE ERROR Here is my

 learning AT&T x86 assembly language. write an assembly program which takes an integer n, then print itdigit by digit. FIND THE ERROR

Here is my code:

.data
.equ STDIN,0
.equ STDOUT,1
.equ READ,3
.equ WRITE,4
.equ EXIT,1
.equ SUCCESS,0

digit:
.long 0
power:
.long 1
ten:
.long 10
.text

.global _start
_start:
call convert
call output

convert:

output:
#eax contains the integer number
movl $56, %eax
movl %eax, %ecx
movl power, %eax
xor %ebx, %ebx

while:
cmp %eax, %ecx
jl done2
inc %ebx
mull ten
jmp while

done2:
xor %edx, %edx
divl ten
movl %eax, %ebx
movl %ecx, %eax

print:
xor %edx, %edx
divl %ebx
pushl %edx
pushl %ebx
addb $48, %al
movb %al, digit
# write to screen
movl $1, %edx
movl $digit, %ecx
movl $STDOUT, %ebx
movl $WRITE, %eax
int $0X80 #like cout
popl %ebx
movl %ebx, %eax
xor %edx, %edx
divl ten
cmp $0, %eax
je done3
movl %eax, %ebx
popl %eax
jmp print

done3:

ret

done:
#exit gracefully
movl $EXIT, %eax # System call numberO
movl $SUCCESS, %ebx # Argument is 0
int $0x80 #System call code
ret

Step by Step Solution

3.42 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

There are a few errors in the provided assembly code Heres a corrected version with explanations of ... View full answer

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!