没有很多 GAS 组装教程,所以我非常迷茫。这只是一个简单的程序,在用户输入基数和指数后计算结果。但它不起作用,我认为我的比较语句有问题。您的帮助将不胜感激!谢谢!:)
.section .data
input1: .ascii "Input base number: \0"
input1Len: .long .-input1
input2: .ascii "Input exponent: \0"
input2Len: .long .-input2
newline: .ascii "\n\0"
newlineLen: .long .-newline
output: .ascii "result = "
outputLen: .long .-output
.section .bss
.lcomm base, 1
.lcomm exponent, 1
.lcomm result, 1
.lcomm one, 1
.section .text
.globl _start
_start:
#prompt 1st number
movl $4,%eax
movl $1,%ebx
movl $input1,%ecx
movl input1Len, %edx
int $0x80
#get 1st input number
movl $3, %eax
movl $1, %ebx
movl $base, %ecx
int $0x80
#write 1st input number
movl $4,%eax
movl $1,%ebx
movl $base,%ecx
int $0x80
#prompt 2nd number
movl $4,%eax
movl $1,%ebx
movl $input2,%ecx
movl input2Len, %edx
int $0x80
#get 2nd input number
movl $3, %eax
movl $1, %ebx
movl $exponent, %ecx
int $0x80
#write 2nd input number
movl $4,%eax
movl $1,%ebx
movl $exponent,%ecx
int $0x80
#move base to result
movl (base), %eax
movl %eax, (result)
#check if exponent==1
movl (exponent), %ecx
subl $0x30, %ecx
cmpl $1, %ecx
while:
movl (base), %eax
movl (result), %ebx
subl $0x30, %eax
subl $0x30, %ebx
#multiply result and base, then update result
imull %eax, %ebx
movl %ebx, (result)
addl $0x30, %ebx
movl %ebx, (result)
#subtract 1 from ecx, which is the exponent
subl $1, %ecx
#compare if ecx is greater than 1
cmpl $1, %ecx
jg while
print:
#write output
movl $4,%eax
movl $1,%ebx
movl $output,%ecx
movl outputLen, %edx
int $0x80
movl $4,%eax
movl $1,%ebx
movl $result,%ecx
movl $1, %edx
int $0x80
movl $4,%eax
movl $1,%ebx
movl $newline,%ecx
movl newlineLen, %edx
int $0x80
_exit:
movl $1, %eax
movl %ecx, %ebx
int $0x80