assembly

How do I print an address in x86 NASM assembly language? [duplicate]

拜拜、爱过 提交于 2021-01-27 18:53:17
问题 This question already has answers here : How to convert a binary integer number to a hex string? (2 answers) Closed 1 year ago . I am trying to print address of variable in NASM x86 assembly. When I assemble this code it assembles fine, however when I run this code it prints two characters instead of the address. section .bss Address: RESB 4 section .data variable db 1 section .text global _start _start: mov eax , variable ; variable Address is stored in eax register mov [Address] , dword eax

Retrieving memory data with non-canonical-address causes SIGSEGV rather than SIGBUS

妖精的绣舞 提交于 2021-01-27 18:46:36
问题 I can not produce a "Bus error" with the following assembly code. Here the memory address I use is not a legal "canonical-address". So, how can I trigger that error? I was running this snippet of code under Ubuntu 20.04 LTS with NASM 2.14.02, but it results in a SIGSEGV segmentation fault on the load, not SIGBUS. global _start section .text _start: mov rax, [qword 0x11223344557788] mov rax, 60 xor rdi, rdi syscall Corresponding X86-64 assembly code after compiling: Disassembly of section

Assembly imul signed

依然范特西╮ 提交于 2021-01-27 17:51:56
问题 thx for help my question is about ax value received from code below? mov al,22h mov cl,0fdh imul cl Actual machine result: ff9a What I expected: 00:9a (by multiplying in binary) The first number is 22h so its 34 decimal its already unsigned the second number is fd in binary its goes like 11111101 so its signed that mean its like -3 so 22* -3 its 66; and -66 on signed 9a so why there is ff at the beginning 回答1: imul cl does AX = AL * CL , producing a full 16-bit signed product from 8-bit

MinGW: Linking with -nostdlib produces invalid executable

≡放荡痞女 提交于 2021-01-27 16:42:29
问题 I've spent the last couple of hours trying to link a simple x86 assembly program without any of the CRT initialization code using MinGW. I want the executable to only contain the _main method listed below and a single import of the ExitProcess kernel function. Opening the various generated files in a disassembler reveals that _main is indeed the entry point and the import table contains an import of ExitProcess (without the name decorations) from KERNEL32.dll , however Windows won't load the

MinGW: Linking with -nostdlib produces invalid executable

白昼怎懂夜的黑 提交于 2021-01-27 16:35:52
问题 I've spent the last couple of hours trying to link a simple x86 assembly program without any of the CRT initialization code using MinGW. I want the executable to only contain the _main method listed below and a single import of the ExitProcess kernel function. Opening the various generated files in a disassembler reveals that _main is indeed the entry point and the import table contains an import of ExitProcess (without the name decorations) from KERNEL32.dll , however Windows won't load the

What causes “x.asm:(.text+0xd): undefined reference to `y'”?

我们两清 提交于 2021-01-27 16:12:51
问题 For a long time I had not programmed with C and Assembler (about 2 years). Now I have decided to start again but I would like to do something much more complicated. I thought about creating a simple kernel. Now I found this source code on the internet: boot.asm: global loader extern kernel_main MAGIC equ 0xbad FLAGS equ 0x3 CHECKSUM equ -(MAGIC+FLAGS) section .text align 4 dd MAGIC dd FLAGS dd CHECKSUM loader: call kernel_main cli quit: hlt jmp quit kernel.c: void print(char *text) { char

What causes “x.asm:(.text+0xd): undefined reference to `y'”?

心不动则不痛 提交于 2021-01-27 16:10:43
问题 For a long time I had not programmed with C and Assembler (about 2 years). Now I have decided to start again but I would like to do something much more complicated. I thought about creating a simple kernel. Now I found this source code on the internet: boot.asm: global loader extern kernel_main MAGIC equ 0xbad FLAGS equ 0x3 CHECKSUM equ -(MAGIC+FLAGS) section .text align 4 dd MAGIC dd FLAGS dd CHECKSUM loader: call kernel_main cli quit: hlt jmp quit kernel.c: void print(char *text) { char

Null-terminated string, opening file for reading

眉间皱痕 提交于 2021-01-27 15:59:57
问题 I'm experimenting with sys_open syscall and I get file descriptor for reading. Here is my program: SYS_exit equ 0x3C SYS_open equ 0x02 O_RDONLY equ 0x00 O_WRONLY equ 0x01 O_RDWR equ 0x02 section .text global _start _start: mov eax, SYS_open mov rdi, file_name mov rsi, O_RDONLY mov rdx, 0x00 syscall mov eax, SYS_exit mov rdi, 0x00 syscall section .data file_name: db '/path/to/test\0' So when I ran strace ./bin I got the output: open("/path/to/test\\0", O_RDONLY) = -1 ENOENT (No such file or

Null-terminated string, opening file for reading

做~自己de王妃 提交于 2021-01-27 15:59:08
问题 I'm experimenting with sys_open syscall and I get file descriptor for reading. Here is my program: SYS_exit equ 0x3C SYS_open equ 0x02 O_RDONLY equ 0x00 O_WRONLY equ 0x01 O_RDWR equ 0x02 section .text global _start _start: mov eax, SYS_open mov rdi, file_name mov rsi, O_RDONLY mov rdx, 0x00 syscall mov eax, SYS_exit mov rdi, 0x00 syscall section .data file_name: db '/path/to/test\0' So when I ran strace ./bin I got the output: open("/path/to/test\\0", O_RDONLY) = -1 ENOENT (No such file or

What causes “x.asm:(.text+0xd): undefined reference to `y'”?

匆匆过客 提交于 2021-01-27 15:52:24
问题 For a long time I had not programmed with C and Assembler (about 2 years). Now I have decided to start again but I would like to do something much more complicated. I thought about creating a simple kernel. Now I found this source code on the internet: boot.asm: global loader extern kernel_main MAGIC equ 0xbad FLAGS equ 0x3 CHECKSUM equ -(MAGIC+FLAGS) section .text align 4 dd MAGIC dd FLAGS dd CHECKSUM loader: call kernel_main cli quit: hlt jmp quit kernel.c: void print(char *text) { char