assembly

How does the linker find the main function?

空扰寡人 提交于 2021-02-07 06:25:06
问题 How does the linker find the main function in an x86-64 ELF-format executable? 回答1: A very generic overview, the linker assigns the address to the block of code identified by the symbol main . As it does for all the symbols in your object files. Actually, it doesn't assign a real address but assigns an address relative to some base which will get translated to a real address by the loader when the program is executed. The actual entry point is not likely main but some symbol in the crt that

Delphi assembler constant 'eof'

孤者浪人 提交于 2021-02-07 05:37:25
问题 There seems to be an undocumented constant eof in asm block context. This was tested using Delphi 7. program TestEof; {$APPTYPE CONSOLE} var example : Integer; begin asm mov example, eof end; writeln(example); readln; end. This prints out 14 . Where does that constant eof and it's value value $0E or 14 come from? EDIT: this is the compilation result ... call @InitExe // mov example, eof mov [example], $0000000e // writeln(example) mov eax, [$004040a4] mov edx, [example] call @Write0Long call

Assembly: REP MOVS mechanism

蹲街弑〆低调 提交于 2021-02-07 05:28:08
问题 Looking at the following assembly code: MOV ESI, DWORD PTR [EBP + C] MOV ECX, EDI MOV EAX, EAX SHR ECX, 2 LEA EDI, DWORD PTR[EBX + 18] REP MOVS DWORD PTR ES:[EDI], DWORD PTR [ESI] MOV ECX, EAX AND ECX, 3 REP MOVS BYTE PTR ES:[EDI], BYTE PTR[ESI] The book I got the code excerpt from explains the first REP MOVS as copying over 4-byte chunks, with the second REP MOVS copying the remaining 2-byte chunk, if it exists. How do the REP MOVS instructions operate? According to MSDN, "The instruction

Difference between memory and register

不羁的心 提交于 2021-02-07 04:35:13
问题 I saw assembly code like, MOV [EAX], EBX the above line, They are mentioned [EAX] is memory and EBX is Register. So, here what is the difference between [EAX] and EBX . What will happen in above instruction. 回答1: In this syntax, brackets around a register means a memory location is used (as source or destination, according to the instruction) with starting address specified at the register (EAX in your case). For example, if EAX contained 1344 before the instruction, value from EBX is copied

What are the advantages of a frame pointer?

我是研究僧i 提交于 2021-02-07 03:51:42
问题 We're studying the MIPS assembler (I guess this question can apply to assembly in general though), and the teacher introduced us to the frame pointer . If I have a function prologue, I used to do directly the stack pointer : addiu $sp, $sp, -8 ; alloc 2 words in the stack sw $s0, 4($sp) ; save caller function $s0 value in the stack sw $ra, ($sp) ; save the return address for the callee function And in the function epilogue: move $v0, $0 ; set 0 as return value lw $s0, 4($sp) ; pick up caller

What are the advantages of a frame pointer?

痴心易碎 提交于 2021-02-07 03:50:26
问题 We're studying the MIPS assembler (I guess this question can apply to assembly in general though), and the teacher introduced us to the frame pointer . If I have a function prologue, I used to do directly the stack pointer : addiu $sp, $sp, -8 ; alloc 2 words in the stack sw $s0, 4($sp) ; save caller function $s0 value in the stack sw $ra, ($sp) ; save the return address for the callee function And in the function epilogue: move $v0, $0 ; set 0 as return value lw $s0, 4($sp) ; pick up caller

Understanding sign and overflow flag in assembly

那年仲夏 提交于 2021-02-07 03:34:34
问题 This question is about the cmp instruction in assembly. I cannot understand how my books reasoning regarding the SF and OF flags. cmp vleft, vright According to my book: For signed integers, there are three flags that are important: the zero (ZF) flag, the overflow (OF) flag and the sign (SF) flag. The overflow flag is set if the result of an operation overflows (or underflows). The sign flag is set if the result of an operation is negative. If vleft = vright , the ZF is set (just as for

Understanding sign and overflow flag in assembly

独自空忆成欢 提交于 2021-02-07 03:31:33
问题 This question is about the cmp instruction in assembly. I cannot understand how my books reasoning regarding the SF and OF flags. cmp vleft, vright According to my book: For signed integers, there are three flags that are important: the zero (ZF) flag, the overflow (OF) flag and the sign (SF) flag. The overflow flag is set if the result of an operation overflows (or underflows). The sign flag is set if the result of an operation is negative. If vleft = vright , the ZF is set (just as for

How to write to screen with video memory address 0xb8000 from real mode?

巧了我就是萌 提交于 2021-02-06 20:02:53
问题 I created simple code to load second sector from hard drive, and then write to whole screen, with spaces with red background. The problem is that always instead of spaces I got @ signs. This is the code: org 0x7C00 bits 16 xor ax,ax mov ds,ax mov es,ax mov bx,0x8000 cli mov ss,bx mov sp,ax sti cld clc xor ah,ah int 0x13 mov bx,0x07E0 mov es,bx xor bx,bx mov ah,0x2 ;function mov al,0x5 ;sectors to read mov ch,0x0 ;track mov cl,0x2 ;sector mov dh,0x0 ;head int 0x13 ;jc error ;mov ah, [0x7E00]

Why use RIP-relative addressing in NASM?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-06 09:25:50
问题 I have an assembly hello world program for Mac OS X that looks like this: global _main section .text _main: mov rax, 0x2000004 mov rdi, 1 lea rsi, [rel msg] mov rdx, msg.len syscall mov rax, 0x2000001 mov rdi, 0 syscall section .data msg: db "Hello, World!", 10 .len: equ $ - msg I was wondering about the line lea rsi, [rel msg] . Why does NASM force me to do that? As I understand it, msg is just a pointer to some data in the executable and doing mov rsi, msg would put that address into rsi .