How to write a byte array correctly in Assembly?
I need to write a byte array, but I don't get it, only written [matrix + 0]
and [matrix + 1]
(what I mean, EAX should be equal 0301070F
), what am I doing wrong?
This is my code:
%include "asm_io.inc"
segment .data
matrix times 4 db 0
segment .bss
segment .text
global asm_main
asm_main:
enter 0,0
pusha
mov eax, 0
mov dword [matrix + 3], 15
mov dword [matrix], 3
mov dword [matrix + 1], 1
mov dword [matrix + 2], 7
mov ah, [matrix]
mov al, [matrix + 1]
rol eax, 16
mov ah, [matrix + 2]
mov al, [matrix + 3]
dump_regs 1
popa
mov eax, 0
leave
ret
and this is the result dump_regs 1
:
Register Dump # 1
EAX = 03010000 EBX = B774FFF4 ECX = BFF7C924 EDX = BFF7C8B4
ESI = 00000000 EDI = 00000000 EBP = BFF7C868 ESP = BFF7C848
EIP = 080484D8 FLAGS = 0282 SF
The caller is a simple program C
:
int main() {
int ret_status;
ret_status = asm_main();
return ret_status;
}
Edited: I found something wrong here, if I execute this code everything works:
mov dword [matrix], 3
mov dword [matrix + 1], 1
mov dword [matrix + 2], 7
mov dword [matrix + 3], 15
but if i execute this doesn't work:
mov dword [matrix + 3], 15
mov dword [matrix], 3
mov dword [matrix + 1], 1
mov dword [matrix + 2], 7
Why?
+3
user3697569
source
to share