0
이것이 정상적으로 작동하는 것처럼 보입니다. 값을 입력 한 직후 세그먼트 화 오류가 계속 발생합니다. 어떤 충고?32bit intel assembly 비교 및 점프
.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가 아닌 .ascii가되는 이유가 있습니까? scanf는 이것이 null로 끝나기를 기대하며, 이것이 seg fault의 원인 일 가능성이 높습니다. –
scanf를 호출하는 동안 충돌이 발생합니까? 그렇지 않다면 정확히 어떤 지시가 내려져야합니다. 그렇다면, 정렬되지 않은 스택이나 James가 언급 한 Null-termination의 부족 때문일 수 있습니다. – ughoavgfhw
inputSpec을 .asciz로 변경했는데 여전히 동일한 위치에서 세분화 오류가 발생합니다. 내 오류가 어디에서 오는 그 날을 이야기하지 그래서 내가 터미널에서 실행 그리고 난 넣어 'pushl \t 속도 pushl \t testPrompt 번호 -> testPrompt : .asciz "값이 % d 개" 호출의 printf ADDL \t $ 8, % esp' scanf가 테스트 한 후에도 해당 지점을 지나쳤으며 새 출력이 없으면 세그먼트 화 오류가 계속 발생합니다 – Josh