0

I have searched: 13. sys_time Syntax: int sys_time(int * tloc) Source: kernel/time.c Action: get time in seconds

This system call has to return the time in seconds from 1970 into eax. My code:

section .text
    global _start
    _start:

    mov eax, 13
    mov ebx, 0 
    int 0x80

    mov [time], eax

    mov edi, dword 0
here:
    mov edx, 1
    mov ecx, time
    add ecx, edi
    add [ecx], dword 48
    mov ebx, 1
    mov eax, 4
    int 0x80

    inc edi
    cmp edi, dword 100
    jne here

    mov ebx, 0
    mov eax, 1
    int 0x80

section .bss
    time resb 100

But when I run this one I see the next: �L�000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

I just wanna get the date. If you know easier way just let me know this. Thanks.

Danny
  • 126
  • 6
  • The 32-bit time result is a binary integer, not unpacked BCD, so adding `'0'` to each byte isn't going to produce a decimal string. I linked a duplicate of how to print an integer. – Peter Cordes May 13 '20 at 17:32
  • Also, your loop is over-complicated. You could do the same (wrong) thing much more simply with `add byte [time+edi], 1` instead of copying the pointer around and doing pointer math with `add`. And make one `write` system call for the whole buffer. – Peter Cordes May 13 '20 at 17:35

0 Answers0