addressing-mode

How i can access a variable data using a variable value in adress like [ var_+[second_byte] ]?

社会主义新天地 提交于 2021-01-29 11:00:55
问题 I got this code: BITS 16 data: bytemap: db 0x0, 0x1, 0x4; pixel_x: db 2; to return the 0x4 value main: ; code... mov al, [bytemap+[pixel_x]]; i need that byte in al register ; more code... jmp main; but nasm returns "expression syntax error", i tryed using mov bl, [pixel_x]; mov al, [bytemap+bl] , but don't work, how the right way to do it? ( if it exists )... 回答1: You need to use pointer-width registers in addressing modes . x86 doesn't have memory-indirect addressing modes, only register

How to do a reverse offset/index in x86 [duplicate]

这一生的挚爱 提交于 2021-01-29 06:12:09
问题 This question already has answers here : Can't subtract registers in an addressing mode? (3 answers) Subtracting registers with an LEA instruction? (1 answer) Referencing the contents of a memory location. (x86 addressing modes) (2 answers) Printing an integer as a string with AT&T syntax, with Linux system calls instead of printf (2 answers) Closed 4 months ago . I am trying to do a negative offset for memory addressing. This is to convert a number to a string and make sure that it doesn't

Assembly - Moving through a register/array with an offset of 5

放肆的年华 提交于 2021-01-29 05:20:53
问题 Quick question. This code will not compile: mov eax, dword [rbx+rsi*5] I don't expect it to, with the explaination that mov and multiplication are two different CPU operations. The only reason it can be achieved is through bit-shifting. However, this does compile: mov eax, dword [lst+rsi*5] With "lst" being a variable array. It also produces output when used in context (so the code compiles AND runs). What's the explanation for why this works? yasm -Worphan-labels -g dwarf2 -f elf64 NAME.asm

Square Brackets ? why are these used in LEA?

喜你入骨 提交于 2021-01-24 08:18:13
问题 In assmebly the square brackets seem to have the same meaning as * in C. They are used to dereference a pointer. Dereferencing a pointer means going to refer to a specific memory location to read or write it. So it is quite logical to use square brackets in the case of a MOV. But what is the logical reason why they also use it for LEA. LEA EAX, [EBP -4], looks like dereferencing a pointer, ebp - 4, to refer to the pointed memory location but it will not read the value contained in the

What is the “-4” for in assembler: movl $1, -4(%rbp) [duplicate]

我怕爱的太早我们不能终老 提交于 2020-12-15 07:06:37
问题 This question already has answers here : What does the bracket in `movl (%eax), %eax` mean? (3 answers) What does a hexadecimal number, with a register in parenthesis mean in Assembly? (1 answer) Closed 22 days ago . int x=1; int y=2; int z=3; turns into movl $1, -4(%rbp) movl $2, -8(%rbp) movl $3, -12(%rbp) What is the -4,-8,-12 for ? Why is it going by 4's? 4 bytes = 32 bits? 回答1: -4 / -8 / -12 bytes relative to the address held in rbp , which is the pointer to the top of the stack (which

MASM: How to resolve Immediate mode Illegal in 8086 programming?

|▌冷眼眸甩不掉的悲伤 提交于 2020-11-29 10:00:47
问题 I am solving a fundamental question of Assembly Language Programming to add BCD numbers and two ASCII numbers, for that I got that I have to use DAA and AAA instructions respectively, Now I am trying to store the result stored in AX register into my desirable memory location, but not getting that why the following code is giving me error Immediate mode Illegal Below is the code that I have coded till now, please help me that how to eradicate this error PS: I want to move my result into my

Subtracting registers with an LEA instruction?

岁酱吖の 提交于 2020-11-25 02:22:44
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm

Subtracting registers with an LEA instruction?

老子叫甜甜 提交于 2020-11-25 02:22:26
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm

Subtracting registers with an LEA instruction?

大城市里の小女人 提交于 2020-11-25 02:18:48
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm

Subtracting registers with an LEA instruction?

时间秒杀一切 提交于 2020-11-25 02:18:21
问题 Does the LEA instruction support negative displacement? mov rax, 1 lea rsi, [rsp - rax] When I use the above code in my asm file I got the error: $ nasm -f macho64 test.asm $ error: invalid effective address I Know that we can do pointer arithmetic like this in C: void foo(char *a, size_t b) { *(a - b) = 1; } then I assume that: lea rsi, [rsp - rax] will work. And I also try to see what the GCC compiler do by using: $ gcc -S foo.c // foo.c has the function foo(above) in it but my asm