nasm

Why does calling 'pop' in this piece of assembly code cause a segmentation fault?

a 夏天 提交于 2019-12-20 05:01:53
问题 I'm playing around with x86-64 assembly on Mac OS (using NASM 2.09 and 2.13, to catch bugs caused by NASM issues). I'm trying to implement function calls at the moment, and tried using the push and pop instructions, but the pop always seems to cause a segfault: line 10: 41072 Segmentation fault: 11 ./result I've tried adjusting rsp , rbp etc manually, but the pop seems to be the issue. Any help would be appreciated! section .data default rel global start section .text start: mov r12, 4 push

Why does calling 'pop' in this piece of assembly code cause a segmentation fault?

一个人想着一个人 提交于 2019-12-20 05:01:23
问题 I'm playing around with x86-64 assembly on Mac OS (using NASM 2.09 and 2.13, to catch bugs caused by NASM issues). I'm trying to implement function calls at the moment, and tried using the push and pop instructions, but the pop always seems to cause a segfault: line 10: 41072 Segmentation fault: 11 ./result I've tried adjusting rsp , rbp etc manually, but the pop seems to be the issue. Any help would be appreciated! section .data default rel global start section .text start: mov r12, 4 push

nasm assembly: Can't find valid values for all labels after 1004 passes

孤人 提交于 2019-12-20 04:45:54
问题 I am trying to write an x86 assembly code for NASM assembler, which will convert a hexadecimal number into a string and print it. For simplicity I have assumed that my hexadecimal number will only contain digits(eg. 0x1234). Here is the code: print_hex.asm [org 0x7c00] mov dx, 0x1234 call print_hex jmp $ print_hex: push bx push cx push dx push ax mov bx, HEX_STR mov cx, 0x000f mov ax, 0x0000 ; length counter loop: push bx ; save bx and cx, dx ; 0xabcd & 0x000f add bx, 5 ; find position in the

How do labels and dd declarations work in NASM? What's the C equivalent?

痞子三分冷 提交于 2019-12-20 04:30:19
问题 I'm trying to understand what'd be the C equivalent of some nasm idioms like these ones: %define CONSTANT1 1 %define CONSTANT2 2 1) section name_section data align=N v1: dd 1.2345678 v2: dd 0x12345678 v3: dd 32767 v4: v5: dd 1.0 v6: dd 1.0, 2.0, 3.0, 4.0, dd 5.0, 6.0, 7.0, 8.0 2) section name_section bss align=N v7: resd 1 3) global _function_name@0 section name_section code align=N _function_name@0: ... 4) global _g_structure1 global _g_structure2 section name_section data align=N _g

Assembly bit memory limit in arithmetic

℡╲_俬逩灬. 提交于 2019-12-20 04:05:32
问题 I wanted to add the following numbers: 40, 90, 50 and 155 and I get a total of 355. I wanted to experiment and test out whether the register AL will have a bit limit of (2^8) - 1, and when I compiled the code and execute the code, I get decimal of 1376331855. How did that happen? Also, I thought 355 is greater than 255, and as a result should display an overflow exception. I understand if I use MOVZX I will be able to carry the calculation into the higher register of AX. Also, I am very

x86 assembly - optimization of clamping rax to [ 0 .. limit )

ぃ、小莉子 提交于 2019-12-20 03:31:27
问题 I'm writing a simple assembler procedure, which, naturally, aims to be as quick as possible. However, a certain part, which is located in the most nested loop, doesn't seem 'right' and I believe it is possible to come up with cleverer and quicker implementation, maybe even without using conditional jumps. The code implements a simple thing: if rax < 0 then rax := 0 else if rax >= r12 then rax := r12 - 1 And here's my naive implementation: cmp rax, 0 jge offsetXGE mov rax, 0 jmp offsetXReady

Why do we need to disambiguate when adding an immediate value to a value at a memory address

故事扮演 提交于 2019-12-20 02:38:21
问题 Explains that unless we specify a size operator (such as byte or dword ) when adding an immediate value to a value stored at a memory address, NASM will return an error message. section .data ; Section containing initialized data memory_address: db "PIPPACHIP" section .text ; Section containing code global _start ; Linker needs this to find the entry point! _start: 23 mov ebx, memory_address 24 add [ebx], 32 ........................................................ 24: error: operation size

NASM: emit MSW of non-scalar (link-time) value [duplicate]

一个人想着一个人 提交于 2019-12-20 02:33:09
问题 This question already has an answer here : Solution needed for building a static IDT and GDT at assemble/compile/link time (1 answer) Closed 3 months ago . I am attempting to define a constant IDT (Interrupt Descriptor Table) entry in NASM, and to do so, I need to emit into a data table the high word of a double-word address that is not resolved until link time . Is there a way to do it? Here's the interrupt handler: ;;; Interrupt 3 (breakpoint) handler. For now, just poke the screen and halt

How do I wait for a keystroke interrupt with a syscall on Linux?

橙三吉。 提交于 2019-12-20 01:38:40
问题 I want to receive an interrupt when the user presses a special keystroke like F1-12 in my program, which is written in nasm. I simply need to wait for a function keystroke at the start of my main function. I know that this is possible with the BIOS's int 16h , which returns a scancode. How can I do this under Linux? 回答1: The necessary code for this is rather complicated; I eventually figured out how to check for F1 in C with raw ioctl, read, and write. The translation to nasm should be

Is there a simple DWARF CFI represenation for functions that set up a conventional frame pointer?

99封情书 提交于 2019-12-19 18:48:40
问题 I'm programming in a mix of C, C++ and assembly and I'd like to get reliable backtraces from any part of the code. This mostly works fine for the C and C++ code since I can generate debugging info with -g , which for modern x86 compilers and platforms generates DWARF debugging information which means the final binary includes CFI (Call Frame Information). This information allows walking backwards though the functions in the current call stack. It can support complex scenarios such as