Assembly x86 with global main - mov doesn't change variable values

35 Views Asked by At

So, I'm trying to just write the logic and make working code, but when I went to run my code to check what I have so far, all the variables were their initialized values. I went as far as to make the first two executed lines just me putting a number in a register then putting it into a variable that I never touch again - variable still had it's declared value.

Here's the code:

section .data


TRUE        equ 1
FALSE       equ 0

EXIT_SUCCESS    equ 0           ; successful operation
NOSUCCESS   equ 1           ; unsuccessful operation

LF      equ 10
NULL        equ 0
ESC     equ 27

SYS_exit    equ 60          ; system call code for terminate
; -----
;  Variables and constants.

STR_LENGTH  equ 15          ; digits in string, including NULL

newLine     db  LF, NULL

; -----
;  Misc. string definitions.


msg         dd 0


; **********************************************************************************

extern  printf

section .text
global  main
main:


mov eax, 10
mov [msg], eax


;  Done

last:
    mov rax, SYS_exit       ; The system call for exit (sys_exit)
    mov rdi, EXIT_SUCCESS
    syscall

Is there something I'm doing wrong? Is there something I should know about coding with global main rather than global _start? Thanks!

EDIT: I'm compiling with these commands:

yasm -Worphan-labels -g dwarf2 -f elf64 as1.asm -l as1.lst

g++ -g -no-pie -o as1 as1.o -lm

EDIT 2:

Also worth noting, the one time a value DID change was when using the XMM0 register:

    movss   xmm0, dword [Num]
    addss   xmm0, dword [One]           ; + 1.0
    movss   dword [Ans], xmm0

Ans would could out to 1. It was declared the same way as msg, only it had a decimal point:

Ans dd 0.0

I assume this is for floating point arithmetic.

EDIT 3:

This also won't work:

;Declared beforehand:
len         dd  60
racism      dd 0
mov eax, dword [len]
mov [racism], eax
0

There are 0 best solutions below