When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
22 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
What do I need to change here?
Didn't you have it working in #c-help-text minutes ago?
The system time should be a 32-bit register anyway.
How do I use a 32-bit register instead?
if you expect the return value to be 32-bits then use eax, not rax
Ah!
@sturdy quiver
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
;compile
#include <stdio.h>
#include <time.h>
#include <stdint.h>
typedef uint32_t u32;
u32 get_system_time() {
u32 system_time;
__asm__
(
"mov $201, %%eax;"
"xor %%rdi, %%rdi;"
"syscall;"
"mov %%eax, %0"
: "=r"(system_time)
:
: "%eax", "%rdi"
);
return system_time;
}
int main() {
u32 system_time = get_system_time();
printf("Current time ASM: %llu\n", system_time);
printf("Current time TIME.H: %u\n", (unsigned)time(NULL));
return 0;
}
Current time ASM: 1720093164
Current time TIME.H: 1720093164
There we go.
time_t is probably going to be 64 bits
so you are potentially truncating the value
I have never seen a unix timestamp to be larger than 32 bits.
In fact that is why we have the "Year 2038" problem
Could it be larger though? What does the standard say?
;compile ```c
#include <time.h>
#include <stdio.h>
printf("%zu", sizeof(time_t));
8