从高到低的杠杆语言我得到了装配。现在,在一开始,我写了一个简单的年龄计划(我不清楚如何获得系统时间,所以我只是使用了另一个输入)。输入最终输入后,我得到Segmentation Fault(核心转储)。这是我的代码:
section .text
global _start
_start:
mov edx, lenask
mov ecx, ask
mov ebx, 1
mov eax, 4
int 0x80
mov edx, 5
mov ecx, input
mov ebx, 2
mov eax, 3
int 0x80
mov edx, lenask2
mov ecx, ask2
mov ebx, 1
mov eax, 4
int 0x80
mov edx, 5
mov ecx, input2
mov ebx, 2
mov eax, 3
int 0x80
mov eax, input2
mov ebx, input
sub eax, ebx
push eax
mov edx, lenanswer
mov ecx, answer
mov ebx, 1
mov eax, 4
int 0x80
pop eax
mov edx, 7
mov ecx, eax
mov ebx, 1
mov eax, 4
int 0x80
section .data
ask db "What is your age?"
lenask equ $-ask
ask2 db "What is today's year?"
lenask2 equ $-ask2
answer db "The age you were born was: "
lenanswer equ $-answer
section .bss
input resb 5
input2 resb 5
发生的事情的一个例子:
What is your age?45
What is today's year?2015
The age you were born was: Segmentation fault
它应该已经完成:
What is your age?45
What is today's year?2015
The age you were born was: 1970