您好我正在尝试在汇编中创建一个程序:
从键盘上读取一个整数和一个字符并进行一些计算。该计划是关于用水量的。如果输入错误,程序应打印错误消息然后终止。例如,如果我首先给出整数并且为负数,则程序应打印错误并终止。
虽然,它总是打印错误消息,我需要一些帮助......如果有人可以提供帮助,这是我的代码
https://drive.google.com/file/d/0B0HbcT5zQEuGaEYtNUhxYk9GcE0/view?usp=sharing
.Question_typos:
.string "请输入使用类型 (o/O e/E b/B) :"
.Question_kivika: .string "请输入您用过的水量:"
.ScanfStr: .string "%c"
.ScanfStr2: .string "%d"
.Reply: .string "结果是:%d\n"
.Reply_error: .string "无效的数据输入。\n" .text .align 2 .global main
主要的:
.LFB0:
stp x29, x30, [sp, -32]!
add x29, sp, 0
adrp x0, .Question_kivika
add x0, x0, :lo12:.Question_kivika
bl printf
add x1, x29, 28
adrp x0, .ScanfStr2
add x0, x0, :lo12:.ScanfStr2
bl scanf
ldr x21, [x29, 28]
cmp x21, xzr
b.mi error_msg
adrp x0, .Question_typos
add x0, x0, :lo12:.Question_typos
bl printf
add x1, x29, 28
adrp x0, .ScanfStr
add x0, x0, :lo12:.ScanfStr
bl scanf
ldr x20, [x29, 28]
bl compute_bill
mov x21, x22
b result
计算账单:
mov x22, 0
cmp x20, 'o'
b.eq house
cmp x20, 'O'
b.eq house
cmp x20, 'e'
b.eq prof
cmp x20, 'E'
b.eq prof
cmp x20, 'b'
b.eq factory
cmp x20, 'B'
b.eq factory
ret
house:
mov x23, 5
mov x24, 10
smaddl x22, w23, w21, x24
ret
prof:
mov x23, 3
mov x24, 1000
smaddl x22, w23, w21, x24
ret
factory:
mov x23, 1
mov x24, 3000
smaddl x22, w23, w21, x24
ret
结果: mov x1,x21 adrp x0, .Reply add x0, x0, :lo12:.Reply bl printf nop ldp x29, x30, [sp], 32 ret
错误消息:adrp x0, .Reply_error add x0, x0, :lo12:.Reply_error bl printf nop ldp x29, x30, [sp], 32 ret
执行的图片