汇编程序 sysTime 在执行时出错 [英] Assembler sysTime giving error on executing

查看:34
本文介绍了汇编程序 sysTime 在执行时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习汇编程序(Nasm、Linux、Ubuntu 16.4、x86_64)并使用 sys_time 调用 (mov eax, 13) 遇到麻烦.

i'm learning Assembler (Nasm, Linux, Ubuntu 16.4, x86_64) and getting Trouble using the sys_time call (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;

错误信息是(用谷歌翻译) (Written dump ) segfaulting 如果有人知道德语,这里的德语错误消息 Speicherzugriffsfehler (Speicherabzug geschrieben)

The error message is (translated with google) (Written dump ) segfaulting if someone knows german here the German error Message Speicherzugriffsfehler (Speicherabzug geschrieben)

我的想法:也许 resb 为字符串保留了空间,但是如何将整数转换为字符串?还是我必须声明一个整数?还是我的内核坏了?

my thougts: maybe resb reserves space for a string, but how can i convert the Integer to a string?? Or do i have to declare a Integer? or is my kernel broke?

推荐答案

你在一行中有 int 80 而不是 int 80h.并且 ecx/edx 具有其他方式的值.

You have int 80 instead of int 80h on one line. And ecx/edx have the values other way.

打印msg后,下一个代码应该是:

After printing msg the next code should be:

mov eax, 4
mov ebx, 1
mov ecx, time
mov edx, 30
int 80h

(无论如何,它不会做,你所期望的,因为 sys_time 不返回字符串,所以你不能直接显示它).

(It will not do, what you expect, anyway, as the sys_time does not return string, so you can't display it directly).

在 Internet 上检查 sys_time 文档...您应该使用 xor ebx,ebx(NULL 缓冲区指针)调用它,并使用返回的 eax 值.给它缓冲区指针现在是过时的调用方式.这是自 Epoch (1970-01-01 00:00:00 +0000 (UTC)) 以来的秒数.

Checking the sys_time docs on internet... you should call it rather with xor ebx,ebx (NULL buffer pointer), and use the returned eax value. Giving it the buffer pointer is now obsolete way of call. It's number of seconds since Epoch (1970-01-01 00:00:00 +0000 (UTC)).

所以在你的代码的开头你可以这样做:

So at the beginning of your code you can do:

mov eax, 13
xor ebx,ebx
int 80h
mov [time],eax

仍然没有解决如何显示它(我什至不会尝试,取决于您真正想要实现的目标,是否仅针对clib链接就足够了,然后使用C函数格式化时间,或者您想要自己从头开始创建 seconds_number->time_string 格式化程序).

It's still not solving how to display it (nor I will even try, depends what you really want to achieve, whether just linking against clib is enough for you, and then use the C functions to format the time, or you want to create the seconds_number->time_string formatter from scratch on your own).

这篇关于汇编程序 sysTime 在执行时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆