汇编程序 sysTime 在执行时给出错误
Assembler sysTime giving error on executing
我正在学习汇编程序(Nasm、Linux、Ubuntu 16.4、x86_64)
并使用 sys_time 调用 (mov eax, 13).
遇到麻烦
section .bss
time: resb 30;
section .data
msg: db "The Time is:";
msgLen: equ $-msg;
blank: db 0x0a;
blankLen: equ $-blank;
section .text
global _start:
_start:
mov eax, 13;
mov ebx, time;
int 80h;
mov eax, 4;
mov ebx, 1;
mov ecx, msg;
mov edx, msgLen;
int 80h;
mov eax, 4;
mov ebx, 1;
mov edx, time;
mov ecx, 30;
int 80;
mov eax, 4;
mov ebx, 1;
mov ecx, blank;
mov edx, blankLen;
int 80h;
mov eax, 1;
mov ebx, 0;
int 80h;
错误信息是
(用 google 翻译)(Written dump ) segfaulting
如果这里有人懂德语,德语错误消息 Speicherzugriffsfehler (Speicherabzug geschrieben)
我的想法:也许 resb 为字符串保留 space,但我如何将整数转换为字符串??还是我必须声明一个整数?
还是我的内核坏了?
您在一行中有 int 80
而不是 int 80h
。并且 ecx/edx 具有其他方式的值。
打印后 msg
下一个代码应该是:
mov eax, 4
mov ebx, 1
mov ecx, time
mov edx, 30
int 80h
(不会吧,如你所愿,反正sys_time
没有return字符串,所以不能直接显示)。
正在互联网上查看 sys_time 文档...您应该使用 xor ebx,ebx
(NULL 缓冲区指针)来调用它,并使用 returned eax
值.给它缓冲区指针现在是过时的调用方式。这是自大纪元 (1970-01-01 00:00:00 +0000 (UTC)) 以来的秒数。
所以在代码的开头你可以这样做:
mov eax, 13
xor ebx,ebx
int 80h
mov [time],eax
它仍然没有解决如何显示它(我什至不会尝试,取决于你真正想要实现的,是否只是链接到 clib 就足够了,然后使用 C 函数格式化时间,或者你想自己从头开始创建 seconds_number->time_string 格式化程序)。
我正在学习汇编程序(Nasm、Linux、Ubuntu 16.4、x86_64) 并使用 sys_time 调用 (mov eax, 13).
遇到麻烦section .bss
time: resb 30;
section .data
msg: db "The Time is:";
msgLen: equ $-msg;
blank: db 0x0a;
blankLen: equ $-blank;
section .text
global _start:
_start:
mov eax, 13;
mov ebx, time;
int 80h;
mov eax, 4;
mov ebx, 1;
mov ecx, msg;
mov edx, msgLen;
int 80h;
mov eax, 4;
mov ebx, 1;
mov edx, time;
mov ecx, 30;
int 80;
mov eax, 4;
mov ebx, 1;
mov ecx, blank;
mov edx, blankLen;
int 80h;
mov eax, 1;
mov ebx, 0;
int 80h;
错误信息是
(用 google 翻译)(Written dump ) segfaulting
如果这里有人懂德语,德语错误消息 Speicherzugriffsfehler (Speicherabzug geschrieben)
我的想法:也许 resb 为字符串保留 space,但我如何将整数转换为字符串??还是我必须声明一个整数? 还是我的内核坏了?
您在一行中有 int 80
而不是 int 80h
。并且 ecx/edx 具有其他方式的值。
打印后 msg
下一个代码应该是:
mov eax, 4
mov ebx, 1
mov ecx, time
mov edx, 30
int 80h
(不会吧,如你所愿,反正sys_time
没有return字符串,所以不能直接显示)。
正在互联网上查看 sys_time 文档...您应该使用 xor ebx,ebx
(NULL 缓冲区指针)来调用它,并使用 returned eax
值.给它缓冲区指针现在是过时的调用方式。这是自大纪元 (1970-01-01 00:00:00 +0000 (UTC)) 以来的秒数。
所以在代码的开头你可以这样做:
mov eax, 13
xor ebx,ebx
int 80h
mov [time],eax
它仍然没有解决如何显示它(我什至不会尝试,取决于你真正想要实现的,是否只是链接到 clib 就足够了,然后使用 C 函数格式化时间,或者你想自己从头开始创建 seconds_number->time_string 格式化程序)。