nasm

Incorrect NASM indirect addressing assembly on macOS

一笑奈何 提交于 2019-12-12 17:07:52
问题 Assembling the following code on macOS: global start default rel section .text start: lea rdx, [buffer + 0] lea rdx, [buffer + 1] lea rdx, [buffer + 2] lea rdx, [buffer + 3] lea rdx, [buffer + 4] lea rdx, [buffer + 5] lea rdx, [buffer + 6] lea rdx, [buffer + 7] lea rdx, [buffer + 8] section .data buffer: db 0,0,0 using the command nasm -fmacho64 -w+all test.asm -o test.o , yields: (with gobjdump -d test.o ) 0000000000000000 <start>: 0: 48 8d 15 38 00 00 00 lea 0x38(%rip),%rdx # 3f <buffer> 7:

How can I include debug information with nasm?

六月ゝ 毕业季﹏ 提交于 2019-12-12 16:59:54
问题 I have this source code: ; hello.asm a first program for nasm for Linux, Intel, gcc ; ; assemble: nasm -f elf -l hello.lst hello.asm ; link: gcc -o hello hello.o ; run: hello ; output is: Hello World SECTION .data ; data section msg: db "Hello World",10 ; the string to print, 10=cr len: equ $-msg ; "$" means "here" ; len is a value, not an address SECTION .text ; code section global main ; make label available to linker main: ; standard gcc entry point mov edx,len ; arg3, length of string to

(assembly x86 real mode) Data gets “cut off” at the end of the program?

情到浓时终转凉″ 提交于 2019-12-12 15:06:04
问题 This is a follow-up from (nasm x86 real mode) How to write/read strings in boot-loaded sector?. I'm working on a toy OS for x86 real mode in NASM. The 512B boot sector loads another sector with the rest of the code. The problem is that I seem to run out of space at the end of the program. Here's the beginning of the source file: ;;; nasm -f bin -o boot.bin os.asm ;;; qemu-system-x86_64 boot.bin bits 16 section boot, vstart=0x0000 ;; Load next sector. ;; adapted from: ;; https://blog.benjojo

Hooking Int 09h interrupt

ⅰ亾dé卋堺 提交于 2019-12-12 14:52:29
问题 I have a problem hooking int 09h I've changed the pointer to my new Isr, if I debug on windows, the interrupt is triggered every time I push a key. But in VMWare it seems that only is triggered one time and no more. I've tested in DOS 6.22 and happens exactly the same. My code look like this: MyIsr: pusha pushf ;tell PIC that interrupt has finished mov al,0x20 out 0x20,al popf popa iret If I use a USB keyboard can I send the same commands like Ps/2? 回答1: There could be a number of issues here

NASM on Virtual Machine Ubuntu: Cannot execute binary file exec format error

≯℡__Kan透↙ 提交于 2019-12-12 13:22:27
问题 I am getting an error after assembling a simple 64 bit hello world program. I am using the following commands: nasm -f elf64 hello.asm -o hello.o successfull ld -o hello.o hello -m elf_x86_64 successfull ./hello error: Cannot execute binary file exec format error I am executing this in a 64 bit Ubuntu Virtual Machine. I appreciate your help! 回答1: The error: error: Cannot execute binary file exec format error Suggests your system can't understand the executable you are trying to run. In my

x86 Assembly Memory - What does the “add” instruction do?

Deadly 提交于 2019-12-12 13:01:42
问题 Memory Segment Below. On the first add instruction (add eax, 3), it moves the pointer for eax 3 spots to the right. Thus, EAX = 12, 17, A3, 00. (This I understand) But, on the second add instruction (add ebx, 5), it actually adds the value 5 to ebx, making EBX = 12, 17, A3, 05 . Why is that? (Little Endian) 回答1: 'add reg, (something)' adds that value to the register, period. The difference you are seeing is how you are using the registers. As you are doing 'mov ebx,[eax]' you are using the

"relocation R_X86_64_32S against `.bss' can not be used when making a shared object”

笑着哭i 提交于 2019-12-12 11:37:42
问题 I'm absolutely green in this but during classes, teacher gave us file he wrote just for us to run it and it worked fine then, but when I try to do it at home (I use Linux on VirtualBox) and use: nasm -f elf64 hello.asm -o hello.o gcc hello.o -o hello I get an error "relocation R_X86_64_32S against `.bss' can not be used when making a shared object; recompile with -fPIC”. Can someone please explain what to do to make it work? global main extern printf section .data napis: db ' Hello world! -

how to call C functions from assembly routines and link the C and assembly files using nasm and gcc

二次信任 提交于 2019-12-12 10:13:57
问题 I want to call at least 1 C function from assembly. It is because I'm doing my own tiny OS from scratch(out of nothing). The reason i want to call c function from my boot loader. I can understand assembly but poor in writing my own program. So if i could transfer control from assembly procedure to c procedure my job is made easier. So how to link assembly pgm and C program files into one. It is ok for me even if the file size exceeds 512 bytes. I am doing this on Windows 7 with help of mingw

How would I find the length of a string using NASM?

丶灬走出姿态 提交于 2019-12-12 09:53:26
问题 I'm trying to make a program using NASM that takes input from command line arguments. Since string length is not provided, I'm trying to make a function to compute my own. Here is my attempt, which takes a pointer to a string in the ebx register, and returns the length of the string in ecx : len: push ebx mov ecx,0 dec ebx count: inc ecx inc ebx cmp ebx,0 jnz count dec ecx pop ebx ret My method is to go through the string, character by character, and check if it's null. If it's not, I

How can i pass parameters in assembler x86 function call

大兔子大兔子 提交于 2019-12-12 09:34:48
问题 Look at this assembler code. It is designed for 32 bits x86 and will be compiled by nasm ... my_function: pop %eax ... ret main: push 0x08 call my_function I have learned a long time ago that we can use stack for passing parameters between main program and functions. I would expect that eax contains 0x08, but this is false and i can not explain why. How should i do for fetching my function parameters ? 回答1: Firstly, if you are looking to interface with other languages or libraries on your