Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

linux - Assembler sysTime giving error on executing

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;

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

After printing msg the next code should be:

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

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


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

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...