nasm

Why is the value of EDX overwritten when making call to printf?

早过忘川 提交于 2019-12-22 05:26:23
问题 I've written a simple assembly program: section .data str_out db "%d ",10,0 section .text extern printf extern exit global main main: MOV EDX, ESP MOV EAX, EDX PUSH EAX PUSH str_out CALL printf SUB ESP, 8 ; cleanup stack MOV EAX, EDX PUSH EAX PUSH str_out CALL printf SUB ESP, 8 ; cleanup stack CALL exit I am the NASM assembler and the GCC to link the object file to an executable on linux. Essentially, this program is first putting the value of the stack pointer into register EDX, it is then

How to generate assembly code with gcc that can be compiled with nasm

陌路散爱 提交于 2019-12-22 05:13:29
问题 I am trying to learn assembly language as a hobby and I frequently use gcc -S to produce assembly output. This is pretty much straightforward, but I fail to compile the assembly output. I was just curious whether this can be done at all. I tried using both standard assembly output and intel syntax using the -masm=intel . Both can't be compiled with nasm and linked with ld . Therefore I would like to ask whether it is possible to generate assembly code, that can be then compiled. To be more

Help Writing TSR Program(s) in NASM Assembly for DOS

时间秒杀一切 提交于 2019-12-22 04:05:29
问题 I've been trying to write TSR (Terminate-Stay-Resident) programs (in general) in Assembly (16-bit) for MS-DOS. I've read through a Wikipedia page on TSR and also a page on using it specifically in DOS (but it seems to be teaching it in C and not Assembly directly). I've looked at a site with tons of DOS interrupt documentation and find this one, this one, and another most relevant to TSR programs. I can't post all of the links because as a new user I can have up to 2 hyperlinks on a post. So,

Test native x86 programs, building bootable images/drives

不羁的心 提交于 2019-12-21 23:24:08
问题 I have the next problem: I'm working with NASM and building some native and compiling it on this way: nasm -f bin source -o out I'm getting my native program for x86. And now the most interesting, how can I make it bootable and then test it? As I think there are 3 ways to make bootable ( but for me, all they has failed :( ) using mkbt utility ( or another soft which is similar ) to write it to floppy disk building ISO image, with editing bootable sector in it manually write memory sector to

How to compile using nasm on MacOSX

霸气de小男生 提交于 2019-12-21 04:06:25
问题 I am trying to compile and link my first program on Assembler. I try to compile the following code: ; %include "stud_io.inc" global _main section .text _main: xor eax, eax again: ; PRINT "Hello" ; PUTCHAR 10 inc eax cmp eax, 5 jl again Below the console command for compiling and linking a program: -bash-3.2$ nasm -f macho main.asm -o main.o && ld -e _main -macosx_version_min 10.8 -arch x86_64 main.o But the result is: ld: warning: ignoring file main.o, file was built for i386 which is not the

x86 labels and LEA in GDB

☆樱花仙子☆ 提交于 2019-12-21 02:55:14
问题 I"m learning to code in x86 assembly (32-bit at the moment) and I'm struggling to understand the memory model completely. Particularly confusing is the semantics for labels, and the LEA instruction, and the layout of the executable. I wrote this sample program so i could inspect it running in gdb. ; mem.s SECTION .data msg: db "labeled string\n" db "unlabeled-string\n" nls: db 10,10,10,10,10,10,10,10 SECTION .text global _start _start: ; inspect msg label, LEA instruction mov eax, msg mov eax

x86 labels and LEA in GDB

这一生的挚爱 提交于 2019-12-21 02:55:12
问题 I"m learning to code in x86 assembly (32-bit at the moment) and I'm struggling to understand the memory model completely. Particularly confusing is the semantics for labels, and the LEA instruction, and the layout of the executable. I wrote this sample program so i could inspect it running in gdb. ; mem.s SECTION .data msg: db "labeled string\n" db "unlabeled-string\n" nls: db 10,10,10,10,10,10,10,10 SECTION .text global _start _start: ; inspect msg label, LEA instruction mov eax, msg mov eax

What is the best resource for learning (N)ASM?

拟墨画扇 提交于 2019-12-20 10:59:32
问题 I've been wanting to learn assembly for a while now, and although I've tried a few times before, I haven't really been able to get past "Hello, world". Are there any good introductory tutorials to assembly (preferably using NASM, as I use Windows and Linux)? I do have a bit of C knowledge, but mainly code in higher-level languages such as Ruby, Python, C# and JavaScript. 回答1: For my Assembly language class, we're using the book that Bill recommends. My professor also recommended this book:

How to load a kernel from disk with BIOS int 13h in NASM assembly?

泄露秘密 提交于 2019-12-20 10:01:57
问题 I've been stuck with this for weeks now and have no idea where I'm going wrong because NASM hasn't given me any errors. The code is pretty self explanatory because of the comments. this is the code that is loaded from the BIOS ;-------------------------------------------- ; 'boot.asm' ; loaded from BIOS [org 0x7C00] [bits 16] ;-------------------------------------------- main: mov ah, 0x0E ; print function mov al, '.' ; ascii char int 0x10 ; IO int resetdisk: mov ah, 0x00 ; reset function mov

What does ORG Assembly Instruction do?

会有一股神秘感。 提交于 2019-12-20 09:27:09
问题 can anyone give me a comprehensive description about ORG directive? When and why is it used in assembly written applications? Using Nasm on x86 or AMD64. 回答1: ORG is used to set the assembler location counter . This may or may not translate to a load address at link time. It can be used to define absolute addresses, e.g. when defining something like interrupt vectors which may need to be at a fixed address, or it can be used to introduce padding or generate a specific alignment for the