Download Pelles C here: http://www.pellesc.se
_text SEGMENT PARA PUBLIC 'CODE'
_main PROC NEAR
push eax
push offset @152
call _printf
add esp, 8
push 5050
push offset @154
call _printf
add esp, 8
xor eax, eax
ret
_main ENDP
.rdata SEGMENT DWORD PUBLIC 'CONST'
@154 label byte
db 73H, 75H, 6DH, 3DH, 25H, 64H, 0AH, 00H ; 0000 _ sum=%d..
@152 label byte
db 69H, 3DH, 25H, 64H, 0AH, 00H ; 0008 _ i=%d..
.rdata ENDSQuote from: Vortex on April 15, 2026, 10:35:59 AMBy the way, uncommenting the line below will output the correct result :
main:
00000000 4883EC28 sub rsp, 28h
00000004 488D0D00000000 lea rcx, [??_C@_05BKKKKIID@i?$DN?$CFd?6?$AA@]
0000000B BA65000000 mov edx, 65h
00000010 E800000000 call printf
00000015 488D0D00000000 lea rcx, [??_C@_07MJFEPNKA@sum?$DN?$CFd?6?$AA@]
0000001C BABA130000 mov edx, 13BAh
00000021 E800000000 call printf
00000026 31C0 xor eax, eax
00000028 4883C428 add rsp, 28h
0000002C C3 ret
As Vortex mentioned, this was missingmov edx, 65hQuote from: John Z on April 14, 2026, 04:43:36 PMHi ander_cc,Yes, It really embarrassed me at that time. I realized I had forgotten to turn off the optimization. Then I explained the reason to my students, and turned off optimization to test the code again, and used gcc -o2 to test the code again.
A good lesson there similar to a lawyers credo "In Court don't ask a question if you don't already know the answer" the corollary to teaching, esp programing, is "In classroom don't use an example you haven't tested"(half kidding you, no offense meant)
But seriously yes there have been, and are issues, with using the optimizations and extensive testing is always needed for these. I have many programs using optimizations successfully.
Perhaps Pelle can find the cause of this short program, meanwhile
Your program can use optimizations by using this 'fix':
volatile int i=1;
which, as I understand it inhibits the optimizer from making assumptions about i.
John Z
As an aside I would recommend not using any optimizations for teaching. Optimizing should be performed by the students learning programing.
Cheers,
Quote from: italofutura on April 14, 2026, 08:22:10 AMI do not have admin rights on this laptop.
Page created in 0.023 seconds with 11 queries.