sfl-examples/slide-examples/ex18.asm

29 lines
886 B
NASM
Raw Normal View History

2023-12-14 14:12:51 +01:00
;; LEA examples
bits 64
SECTION .data
;; array of 5 elements, each 2B wide (stored in little-endian)
arr1: dw 0x5501, 0x1102, 0x2203, 0x6604, 0x7705
arr2: db 0x01, 0x02, 0x03, 0x04, 0x05
SECTION .text
global _start
_start:
%include "header.asm.inc"
mov rdx, 3 ; element offset (offset 3 --> 4th element)
;mov rax, arr1 + rdx*2 + 1 ; compute pointer (invalid!)
;mov rax, [arr1 + rdx*2 + 1] ; valid, but *deferences* (we don't want this)
lea rax, [arr1]
lea rax, [rax + rdx*2 + 1] ; compute pointer
mov r9b, byte [rax] ; ---> r9b = 0x55
mov r9b, byte [arr1 + 3*2 + 1] ; (as above, but direct assignment)
lea rax, [arr2]
lea rax, [rax + 1*2 + 2] ; compute pointer
mov r9b, byte [rax] ; ---> r9b = 0x05
%include "sysexit.asm.inc"