0
这看起来应该可以工作,但在输入值后我仍然收到分割错误。有什么建议?32位英特尔汇编比较和跳转
.section .data
speed: .int 0
fine: .int 0
points: .int 0
inputPrompt: .asciz "Enter an integer value for speed ==> "
outputPrompt: .asciz "With a speed of %d the fine will be $%d and %d points will be added to your license"
inputSpec: .ascii "%d"
.section .text #read in values
.globl main
main:
nop
pushl $inputPrompt
call printf
addl $4, %esp
#read in speed value
pushl $speed
pushl $inputSpec
call scanf
addl $8, %esp
#-------------------greater than or equal to 86--------------------------
movl speed, %eax
subl $85, %eax
Jg fine4
#-------------------81 - 85---------------------------------------------
movl speed, %eax
subl $80, %eax
Jg fine3
#-------------------76 - 80---------------------------------------------
movl speed, %eax
subl $75, %eax
Jg fine2
#-------------------71 - 75---------------------------------------------
movl speed, %eax
subl $70, %eax
Jg fine1
#-----------------less than 71-----------------------------------------------
movl $0, fine
movl $0, points
JMP output
#---------------------71 - 75-------------------------------------------
fine1:
movl $60, fine
movl $2, points
JMP output
#---------------------76 - 80-------------------------------------------
fine2:
movl $90, fine
movl $3, points
JMP output
#---------------------81 - 85-------------------------------------------
fine3:
movl $120, fine
movl $4, points
JMP output
#---------------------less than or equal to 86------------------------------------------
fine4:
movl $150, fine
movl $6, points
#----------------------------------------------------------------
output:
pushl points
pushl fine
pushl speed
pushl outputPrompt
call printf
addl $8, %esp
#-----------------------------------------------------------------
call exit
是否有一个原因,inputSpec是.ascii而不是.asciz? scanf预计这将以null结尾,这可能是seg故障的原因。 –
调用scanf期间崩溃了吗?如果没有,那究竟是哪一条指令。如果是这样,那么它可能来自一个未对齐的堆栈,或者来自詹姆斯提到的没有终结的终结。 – ughoavgfhw
我将inputSpec更改为.asciz,并且在看似相同的位置仍然出现分段错误。我在终端运行它所以它不是告诉我在哪里,我的错误是来自我把 'pushl \t速度 pushl \t testPrompt# - > testPrompt:.asciz“的值为%d” 调用printf ADDL \t $ 8,%esp' 在scanf之后测试它是否已经超过了这一点,并且它保持了分割错误而没有新的输出 – Josh