I am trying to learn assembly, so the code may not be entirely correct. When running the assembly code, i expect it to print the numbers 321 132 123 on separate lines. When I run the program on git bash and windows command line, I get the expected behaviour. However, when I run it using Cmder console emulator, it only prints 321. I have not been able to find the reason why. Cmder has the following return code: -1073741819
The assembly code is below. I run it on Windows 10 and create an executable as such:
NASMLINK=/nologo /subsystem:console /defaultlib:msvcrt.lib /defaultlib:legacy_stdio_definitions.lib /defaultlib:Kernel32.lib
nasm -f win64 -o Test.obj Test.asm
link $(NASMLINK) Test.obj /OUT:Test.exe
bits 64
default rel
segment .data
format: db "%lld", 0xa, 0x0
segment .text
global main
extern printf
PrintInt:
push rbp
mov rbp, rsp
sub rsp, 40
mov rdx, rcx
lea rcx, [format]
call printf
add rsp, 40
pop rbp
ret
Test:
push rbp ;Edit1
mov rbp, rsp ;Edit1
sub rsp, 200
mov r8, 132
mov rcx, r8
call PrintInt
add rsp, 200
pop rbp ;Edit1
xor rax, rax;Edit1
ret
main:
push rbp
mov rbp, rsp
sub rsp, 200
mov r8, 321
mov rcx, r8
call PrintInt
call Test
mov r8, 123
mov rcx, r8
call PrintInt
add rsp, 200
pop rbp
xor rax, rax
ret
Edit1
I found that by deleting the lines commented Edit1
then it will run correctly in all command lines. However, I still do not understand why the command lines behave differently when the Edit1
lines are there.