Question
Hi!
I implemented the compiler to and including chapter 138. I compared my code to the git hub version and all was conforming. When I run the test program, however, I get significantly different results to those in the recording:
test.c ->
int test()
{
int b = *a;
}
Compiler terminal output ->
section .data
section .text
global test
; test function
test:
push ebp
mov ebp, esp
sub esp, 18380445687218192
add esp, 18380445687218192
pop ebp
ret
section .rodata
everything compiled fine
Can you imagine what is going wrong? Particularly the HUGE number after add esp and sub esp.
I'm working under Windows with a version of gcc and VS Code.
Up to now, all successful compilations ran OK.
Thanks in advance
Steve Smith
Answered by Daniel McCarthy
Instructor
Hey Stephen,
It sounds to me like you could of derefrenced a pointer or are pointing to the wrong memory address that is why the number seems so big. Put a breakpoint on the add esp and sub esp lines and examine the pointer your passing. Compare your code with mine using GIT rather than manual comparsion and the mistake will become more clear.
Your welcome please let me know if you have any trouble debugging the issue
Thanks
Follow-up by Stephen Smith
Question author
Hi Daniel,
I did some research on the internet and discovered that there is some discussion on the interpretation of format "%lld". Depending on the version of the gcc and the word-length of the system, this can work properly or not, particularly with 64 bit systems.
I first tried format "%d" which gave me the correct solution (16). But the argument to be output is "long long". I tried casting the argument to long long, which indeed delivered the correct value of 16. I presume this is a compiler bug affecting my version of gcc.
In future I will remember to cast the argument under similar circumstances.
Regards and thanks
Steve.
Answered by Daniel McCarthy
Instructor
No worries let me know if you have any more questions
Thanks