N
N
newuser88882020-10-09 19:38:22
assembler
newuser8888, 2020-10-09 19:38:22

Why doesn't the transfer of the array word to the register (gas syntax) work?

.data
arrayW: .word 5,10,15,20

.text
.globl _start
_start:

leaw arrayW, %si
movw (%si), %ax


pushl $0
subl $4, %esp
movl $1, %eax
int $0x80
.end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2020-10-09
@newuser8888

Why does not it work
leaw arrayW, %si
movw (%si), %ax


Because you're trying to address a 16-bit register in a 32-bit program.
This is how it works great:
leal arrayW, %esi
movw (%esi), %ax

:
$ gcc -m32 -static -nostartfiles load.s -o load
$ gdb ./load
(gdb) b _start
Breakpoint 1 at 0x8049000
(gdb) r
Starting program: /home/jcmvbkbc/tmp/toster/load

Breakpoint 1, 0x08049000 in _start ()
(gdb) si
0x08049006 in _start ()
(gdb) 
0x08049009 in _start ()
(gdb) p/x $esi
$1 = 0x804a000
(gdb) p/x $ax
$2 = 0x5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question