General Category > Sol_Asm
RIP addressing
(1/1)
mineiro:
This is my first post, I'm not a bot. My english language is poor, so be patience while reading, I'm learning english language alone on an autodidact way. I'm from Brazil.
Hello Sir Bogdan,
I have done some tests about rip relative address on linux x86-64, we have talked about this before, here are some outputs.
yasm and as assembler output this:
--- Code: ---0000000000000000 <_start>:
0: 8a 05 08 00 00 00 mov al,BYTE PTR [rip+0x8] # e <_start+0xe>
6: 66 8b 05 00 00 00 00 mov ax,WORD PTR [rip+0x0] # d <_start+0xd>
d: 8b 05 00 00 00 00 mov eax,DWORD PTR [rip+0x0] # 13 <_start+0x13>
13: 48 8b 05 08 00 00 00 mov rax,QWORD PTR [rip+0x8] # 22 <_start+0x22>
--- End code ---
solasm is generating this on first pass, and an error on second pass
--- Code: ---0 0 0 0 00000000 .entry _start
0 0 0 0 00000000 _start:
0 0 0 0 00000000 mov al,byte [rip] 8A 05 FC FF FF FF
0 0 0 0 00000006 mov ax,word [rip] 66 8B 05 FC FF FF FF
0 0 0 0 0000000D mov eax,dword [rip] 8B 05 FC FF FF FF
0 0 0 0 00000013 mov rax,qword [rip] 48 8B 05 FC FF FF FF
--- End code ---
Appears that solasm uses signed instead of unsigned?
Thanks a lot sir.
ps: I have seen a minor mistake on manual regarding about structure ends, on STRUC ETH_PACKET structure that ends with ENS.
bogdanontanu:
Hi mineiro,
Thanks for testing Sol_Asm and for caching the error in the manual ;)
What is the source code for that output in yasm and sol_asm?
As I have said before sol_asm does NOT know the symbol "rip" as a register.
This "rip" register does not have an encoding for x64 CPU.
It just appears written like that in disassembly in order to make the reader aware that the encoding is "rip relative" even for data access in x64.
This is a "new" thing in x64 and people like to put emphasis on it.
However it was available for JMP and CALL even for x32 CPU but nobody made a big issue about it.
It helps writing position independent code but that is all about it.
Sol_asm does generate RIP relative addressing by default when in 64 bits ...
if that is what you are after.
Just try with any variable in x64, something like this:
--- Code: ---
.use64
.data
my_var dq 1234h
.code
mov rax,[my_var]
--- End code ---
and sol_asm will generate a:
--- Code: --- MOV RAX,[RIP+relative_offset_of_my_var_to_current_rip]
--- End code ---
Nothing special needs to be done in order to use RIP addressing in Sol_Asm.
RIP addressing is enabled by default in x64 mode.
mineiro:
Thanks for answering sir Bogdan, yes, make sense your words.
The source code that I have worked follows:
solasm
--- Code: ---section "text" class_code alias ".text"
.USE64
.text
.entry _start
_start:
mov al,byte [rip]
mov ax,word [rip]
mov eax,dword [rip]
mov rax,qword [rip]
--- End code ---
yasm
--- Code: ---;command line: yasm -f elf64 -o obj.o obj.asm
section .text
global _start
_start:
mov al,byte [rip]
mov ax,word [rip]
mov eax,dword [rip]
mov rax,qword [rip]
--- End code ---
as
--- Code: ---#command line: as -o quiz.o quiz.asm
.intel_syntax noprefix
.text
.global _start
_start:
mov al,byte ptr [rip]
mov ax,word ptr [rip]
mov eax,dword ptr [rip]
mov rax,qword ptr [rip]
--- End code ---
To archieve that on solasm after read your post I have done this source code
--- Code: ---;sol_asm2 -elf64 quiz.solasm quiz.o
section "text" class_code alias ".text"
.USE64
.text
.entry _start
_start:
mov al,byte [one]
one:
mov ax,word [two]
two:
mov eax,dword [three]
three:
mov rax,qword [four]
four:
--- End code ---
But disassembled code is not equal, maybe I'm doing something wrong but have some displacement:
--- Code: ---$ yasm -f elf64 -o quiz.o quiz.yasm
$ ld -s -m elf_x86_64 -o quiz quiz.o
$ objdump -d -Mintel quiz.o
0000000000000000 <_start>:
0: 8a 05 00 00 00 00 mov al,BYTE PTR [rip+0x0] # 6 <_start+0x6>
6: 66 8b 05 00 00 00 00 mov ax,WORD PTR [rip+0x0] # d <_start+0xd>
d: 8b 05 00 00 00 00 mov eax,DWORD PTR [rip+0x0] # 13 <_start+0x13>
13: 48 8b 05 00 00 00 00 mov rax,QWORD PTR [rip+0x0] # 1a <_start+0x1a>
--- End code ---
--- Code: ---$ sol_asm2 -elf64 quiz.solasm quiz.o
$ ld -s -m elf_x86_64 -o quiz quiz.o
$ objdump -d -Mintel quiz.o
0000000000000000 <_start>:
0: 8a 05 02 00 00 00 mov al,BYTE PTR [rip+0x2] # 8 <_start+0x8>
6: 66 8b 05 09 00 00 00 mov ax,WORD PTR [rip+0x9] # 16 <_start+0x16>
d: 8b 05 0f 00 00 00 mov eax,DWORD PTR [rip+0xf] # 22 <_start+0x22>
13: 48 8b 05 16 00 00 00 mov rax,QWORD PTR [rip+0x16] # 30 <_start+0x30>
--- End code ---
I debug both programs and are generating the same expected results.
Again, thanks a lot sir, I'm enjoying a lot solasm.
bogdanontanu:
Nice to hear that you enjoy sol_asm ;)
Yes, RIP relative addressing does involve some displacement even if that displacement is zero ;)
Navigation
[0] Message Index
Go to full version