nasm

Comparing variables in NASM Assembly

僤鯓⒐⒋嵵緔 提交于 2021-01-28 07:36:27
问题 Serious trouble trying to get this working .. just starting NASM assembly so sorry if this is a noob of an issue, but any help is appreciated thankyou! Trying to get the two variables to render equal so the jump after cmp works. This is frustrating me greatly, as the direct values ( if a mov eax and ebx to be "5" ) it works so is it an address problem? I'm not sure. section .data str_equal db "Equal!", 0xA len_equal equ $ - str_equal str_number_a db "5" str_number_b db "5" section .text

Comparing variables in NASM Assembly

夙愿已清 提交于 2021-01-28 07:19:23
问题 Serious trouble trying to get this working .. just starting NASM assembly so sorry if this is a noob of an issue, but any help is appreciated thankyou! Trying to get the two variables to render equal so the jump after cmp works. This is frustrating me greatly, as the direct values ( if a mov eax and ebx to be "5" ) it works so is it an address problem? I'm not sure. section .data str_equal db "Equal!", 0xA len_equal equ $ - str_equal str_number_a db "5" str_number_b db "5" section .text

Writing a putchar in Assembly for x86_64 with 64 bit Linux?

旧城冷巷雨未停 提交于 2021-01-28 06:10:27
问题 I am trying to use the write syscall in order to reproduce the putchar function behavior which prints a single character. My code is as follows, asm_putchar: push rbp mov rbp, rsp mov r8, rdi call: mov rax, 1 mov rdi, 1 mov rsi, r8 mov rdx, 1 syscall return: mov rsp, rbp pop rbp ret 回答1: From man 2 write , you can see the signature of write is, ssize_t write(int fd, const void *buf, size_t count); It takes a pointer ( const void *buf ) to a buffer in memory. You can't pass it a char by value,

NASM - is this the address, value?

风格不统一 提交于 2021-01-27 22:53:52
问题 TL;DR Is [memloc] referring to the value or the address? If it's referring to either, then why does it work both as a value and an address? (see code below, lines 4 and 5) Full question... Sorry for the long question. I'm confused by label dereferencing in NASM. Take this example: 01| section .text 02| ; exiting the program with exit code "15" 03| 04| mov [memloc], 15 ; move 15 into memloc 05| push [memloc] ; push memloc on stack 06| mov eax, 1 ; prepare exit syscall 07| call kernel ; invoke

add 1 byte immediate value to a 2 bytes memory location

好久不见. 提交于 2021-01-27 21:00:36
问题 The add instruction documentation from this page says the following: Notice the two instructions that I highlighted. I tried the following code in NASM (which conforms with the first highlighted instruction): add WORD [myvar], BYTE 0xA5 But I got the following error: warning: signed byte value exceeds bounds What am I doing wrong? 回答1: The 8-bit immediate operand (denoted here by imm8 ) is sign-extended into 16 (or 32) bits to match the size of the other operand ( r/m16 or r/m32 ,

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

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