nasm

Calling the C-function _printf from NASM causes a Segmentation Fault

北城余情 提交于 2021-02-05 11:35:31
问题 I've been trying to learn 64-bit assembly on both Mac-OS and Windows using NASM. My code is extern _printf section .data msg db "Hello World!", 10, 0 section .text global _main _main: mov rax, 0 mov rdi, msg call _printf mov rax, 0x2000001 mov rdi, 0 syscall and I compile it with nasm -f macho64 -o main.o main.asm gcc -o main main.o While trying to call _printf , I got the error Segmentation fault: 11 When I remove the call to _printf , my code runs fine. Why does the call to _printf cause a

NASM says “Invalid combination of opcode and operands”

白昼怎懂夜的黑 提交于 2021-02-05 11:33:05
问题 I just started learning assembly programming. I am using NASM on linux. I wrote this code that's basically meant to calculate the somethingth power of something and I know it's probably not exactly good, but I really don't care at this point, all I want is just SOME idea why I keep getting that error, because I have tried to modify and switch operands and operations and everything in the section where the problem is, but if anything that only gave me more error messages. As I said, I'm really

Why do my results different following along the tiny asm example?

荒凉一梦 提交于 2021-02-05 09:15:30
问题 I'm reading this page https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html This is one of the example ; tiny.asm BITS 32 GLOBAL _start SECTION .text _start: mov eax, 1 mov ebx, 42 int 0x80 Here we go: $ nasm -f elf tiny.asm $ gcc -Wall -s -nostdlib tiny.o $ ./a.out ; echo $? 42 Ta-da! And the size? $ wc -c a.out 372 a.out However I don't get the same results. I tried nasm -f elf64 and then tried -m32 on gcc (then again on clang). No matter what I try I can not get it to be the tiny

Why do my results different following along the tiny asm example?

梦想的初衷 提交于 2021-02-05 09:15:06
问题 I'm reading this page https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html This is one of the example ; tiny.asm BITS 32 GLOBAL _start SECTION .text _start: mov eax, 1 mov ebx, 42 int 0x80 Here we go: $ nasm -f elf tiny.asm $ gcc -Wall -s -nostdlib tiny.o $ ./a.out ; echo $? 42 Ta-da! And the size? $ wc -c a.out 372 a.out However I don't get the same results. I tried nasm -f elf64 and then tried -m32 on gcc (then again on clang). No matter what I try I can not get it to be the tiny

Why is scanf returning 0.000000 when it is supplied with a double?

久未见 提交于 2021-02-05 09:12:59
问题 I have the following assembly code (written for NASM on Linux): ; This code has been generated by the 7Basic ; compiler <http://launchpad.net/7basic> extern printf extern scanf SECTION .data printf_f: db "%f",10,0 scanf_f: db "%f",0 SECTION .bss v_0 resb 8 SECTION .text global main main: push ebp mov ebp,esp push v_0 ; load the address of the variable push scanf_f ; push the format string call scanf ; call scanf() add esp,8 push dword [v_0+4] ; load the upper-half of the double push dword [v

Why is scanf returning 0.000000 when it is supplied with a double?

不想你离开。 提交于 2021-02-05 09:09:22
问题 I have the following assembly code (written for NASM on Linux): ; This code has been generated by the 7Basic ; compiler <http://launchpad.net/7basic> extern printf extern scanf SECTION .data printf_f: db "%f",10,0 scanf_f: db "%f",0 SECTION .bss v_0 resb 8 SECTION .text global main main: push ebp mov ebp,esp push v_0 ; load the address of the variable push scanf_f ; push the format string call scanf ; call scanf() add esp,8 push dword [v_0+4] ; load the upper-half of the double push dword [v

Why is scanf returning 0.000000 when it is supplied with a double?

我的梦境 提交于 2021-02-05 09:08:52
问题 I have the following assembly code (written for NASM on Linux): ; This code has been generated by the 7Basic ; compiler <http://launchpad.net/7basic> extern printf extern scanf SECTION .data printf_f: db "%f",10,0 scanf_f: db "%f",0 SECTION .bss v_0 resb 8 SECTION .text global main main: push ebp mov ebp,esp push v_0 ; load the address of the variable push scanf_f ; push the format string call scanf ; call scanf() add esp,8 push dword [v_0+4] ; load the upper-half of the double push dword [v

x86 NASM Indirect Far Jump In Real Mode

拈花ヽ惹草 提交于 2021-02-05 08:51:15
问题 I have been messing around with a multi-stage bootloader and I have got all of my code to work, except for the last part: The Jump . I have gotten this code to work out before now but I wanted to make it more modular by replacing this line: jmp 0x7E0:0 With this one: jmp far [Stage2Read + SectorReadParam.bufoff] Instead of hard coding where the code will load in, I wanted to do an indirect jump to it. Here's the rest of my code: ; This is stage 1 of a multi-stage bootloader bits 16 org 0x7C00

How to compile this asm code under linux with nasm and gcc?

时光总嘲笑我的痴心妄想 提交于 2021-02-05 08:24:14
问题 I have the following source snippet from a book that I'm reading now. So I created an asm file and typed exactly. Then used nasm command ( nasm -f elf test.asm ) then tried to compile into an executable file by using gcc ( gcc test.o -o test ) then I get the following error. Error: ld: warning: ignoring file test.o, file was built for unsupported file format which is not the architecture being linked (x86_64) Source code: [BITS 16] [SECTION .text] START: mov dx, eatmsg mov ah, 9 int 21H mov

Allocate writable memory in the .text section

跟風遠走 提交于 2021-02-05 08:12:10
问题 Is it possible to allocate memory in other sections of a NASM program, besides .data and .bss ? Say I want to write to a location in .text section and receive Segmentation Fault I'm interested in ways to avoid this and access memory legally. I'm running Ubuntu Linux 回答1: If you want to allocate memory at runtime , reserve some space on the stack with sub rsp, 4096 or something. Or run an mmap system call or call malloc from libc, if you linked against libc. If you want to test shellcode /