x86-64

GNU Assembler (Mac OS X 64-bit): Illegal instruction: 4 [duplicate]

北慕城南 提交于 2019-12-11 20:39:26
问题 This question already has an answer here : basic assembly not working on Mac (x86_64+Lion)? (1 answer) Closed 5 months ago . I am new to GNU Assembler and I'm trying to execute this piece of code: .globl _main _main: movl $1, %eax movl $0, %ebx int $0x80 This programm should exit by the system call exit ( 1 ). Compiled it (no warnings): gcc test.s But running it gives me the error: Illegal instruction: 4 Thanks for help! 回答1: If you're compiling a 64-bit executable, then you should write

Unlimited stack cannot grow beyond the initial 132KiB if MAP_FIXED involved?

不羁的心 提交于 2019-12-11 19:08:43
问题 I'm running some experiments with stack and the following got me stuck. It can be seen that Linux has initial [stack] mapping 132KiB in size. In case of ulimit -s unlimited we can expand the stack any further if we adjust rsp accordingly. So I set ulimit -s unlimited and ran the following program: PAGE_SIZE equ 0x1000 ;mmap staff PROT_READ equ 0x01 PROT_WRITE equ 0x02 MAP_ANONYMOUS equ 0x20 MAP_PRIVATE equ 0x02 MAP_FIXED equ 0x10 ;syscall numbers SYS_mmap equ 0x09 SYS_exit equ 0x3c section

How does one opcode byte decode to different instructions depending on the “register/opcode” field? What is that? [duplicate]

。_饼干妹妹 提交于 2019-12-11 18:24:34
问题 This question already has answers here : How to read the Intel Opcode notation (3 answers) Closed 12 months ago . How can I determine what an array of bytes will translate into in machine code? I understand that if I see 0f at the start it's a 2 byte instruction, but I see other prefixes and in some disassembly in my x64 debugger I see weird interactions like 48 83 C4 38 and I can see on the opcode reference that 48 says the operand is 64 bytes. But 83 says it can be 7 different instructions

NASM - Macro local label as parameter to another macro

♀尐吖头ヾ 提交于 2019-12-11 17:19:13
问题 I am trying to use a macro (as shown in this tutorial) to print a string. The macro PRINT creates local labels to define the string content ( str ) and length ( strlen ), and then passes these as parameters to a second macro _syscall_write which makes the syscall. However running the code fails and I get a Segmentation fault (core dumped) message. I suspect the problem to be this particular lines, but I don't understand why. mov rsi, %1 ; str mov rdx, %2 ; strln Here is the full code: %macro

NASM Linux x64 | Encode binary to base64

♀尐吖头ヾ 提交于 2019-12-11 17:13:29
问题 I'm trying to encode a binary file into base64. Althrough, I'm stuck at the few steps and I'm also not sure if this is the way to think, see commentaries in code below : SECTION .bss ; Section containing uninitialized data BUFFLEN equ 6 ; We read the file 6 bytes at a time Buff: resb BUFFLEN ; Text buffer itself SECTION .data ; Section containing initialised data B64Str: db "000000" B64LEN equ $-B64Str Base64: db "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" SECTION .text

Move smaller operand into larger operand

亡梦爱人 提交于 2019-12-11 17:01:20
问题 I'm having a little trouble with imagining how data moves into the RAX register. Here is the assembly language: .data dwordVal DWORD 94326732h .code mov rax, 0FFFFFFFF00000000h mov rax, dwordVal I read that you cannot move a smaller operand into a larger operand with MOV. It seems to me that dwordVal would only fill the lower half of the 64 bit rax register, so this would not be permitted. Please correct me if I'm wrong. 回答1: A mov instruction will always fill the destination operand with a

SIMD intrinsic and memory bus size - How CPU fetches all 128/256 bits in a single memory read?

核能气质少年 提交于 2019-12-11 17:01:04
问题 Hello Forum – I have a few similar/related questions about SIMD intrinsic for which I searched online including stackoverflow but did not find good answers so requesting your help. Basically I am trying to understand how a 64 bit CPU fetches all 128 bits in a single read and what are the requirements for such an operation. Would CPU fetch all 128 bits from memory in a single memory operation or will it do two 64 bit reads? Do CPU manufactures demand certain size of the memory bus, example,

What is the aligment requirements for sys_brk

坚强是说给别人听的谎言 提交于 2019-12-11 15:44:08
问题 I'm using sys_brk syscall to dynamically allocate memory in the heap. I noticed that when acquiring the current break location I usually get value similar to this: mov rax, 0x0C mov rdi, 0x00 syscall results in rax 0x401000 The value usually 512 bytes aligned. So I would like to ask is there some alignment requirements on the break value? Or we can misalign it the way we want? 回答1: The kernel does track the break with byte granularity. But don't use it directly for small allocations if you

Wait for keypress Assembly NASM, Linux

社会主义新天地 提交于 2019-12-11 13:58:09
问题 I'm working on a Hello World in Assembly for x86-64. I have managed to create one that finishes when Enter key is pressed, but I have to finish it when ANY key is pressed. This is the code for waiting the ENTER Key: mov rax, 0 mov rdi, 0 mov rdx, 1 syscall I can't use any int xh or something like that. Only syscalls. Thanks! 回答1: I've answered a similar question before, and gave C code that would work directly with system calls to do what you wanted. Here's a translation of that code to nasm,

Are rdi and rsi caller saved or callee saved registers?

不打扰是莪最后的温柔 提交于 2019-12-11 12:53:00
问题 From the wikipedia x86 calling convention, it says that for the Microsoft x64 calling convention: The registers RBX, RBP, RDI, RSI , RSP, R12, R13, R14, and R15 are considered nonvolatile (callee-saved). But for System V AMD64 ABI: If the callee wishes to use registers RBX, RBP, and R12–R15, it must restore their original values before returning control to the caller. It did not mention anything about rdi and rsi. I also read that %rax, %rcx, %rdx, %rdi, %rsi , %rsp, and %r8-r11 are