nasm

Why does nasm use 0x89 when it assembles a MOV instruction between registers?

旧城冷巷雨未停 提交于 2019-12-11 11:22:59
问题 Why does NASM use 0x89 opcode (137) when it assembles a MOV instruction between two registers? Here is an example of code assembled using NASM: 55 push ebp 89E5 mov ebp, esp 83EC04 sub esp, byte +0x4 31C0 xor eax, eax C9 leave C3 ret I wanted something like this: 55 push ebp 8BEC mov ebp, esp 83EC04 sub esp, byte +0x4 33C0 xor eax, eax C9 leave C3 ret The reason I wanted 0x8B was: if you view the binary representation of the MOV instruction, it looks like this in NASM: Opcode Mod Reg R/M

Converting fractions to decimals NASM

拜拜、爱过 提交于 2019-12-11 10:57:38
问题 So I have fixed a lot since my last post but I am still not getting the result. We are working on the 8086 microprocessor and NASM assembler. My code works great right up until it is about to give the result. It will display the 3rd message "The number is: " and prints the decimal point, "." but it won't print any numbers after that and I can't type or exit the program or anything. I have to close DOSBox and run it again. Please help. org 100h ; program converts fraction, M/N, to decimal,

How to use malloc and free in 64-bit NASM?

故事扮演 提交于 2019-12-11 09:54:55
问题 In 64-bit NASM, I'm allocating a memory block of 8000 bytes using malloc() from the C library, and when I'm finished with it, I deallocate it by calling free(). My research has come up with a lot of conflicting information about how to do this in 64-bit NASM, and much of the information is 32-bit, where the calling convention is different, or it's C or C++, not NASM. I think I have the malloc part right, but I'm not sure about the free part. I'm posting this question because I don't want to

How does this assembly bootloader code work?

十年热恋 提交于 2019-12-11 09:41:51
问题 I have the following code in a file ( kernel.asm ): bits 32 section .text ;multiboot spec align 4 dd 0x1BADB002 ;magic dd 0x00 ;flags dd - (0x1BADB002 + 0x00) ;checksum. m+f+c should be zero global start extern k_main ;this is defined in the c file start: cli ;block interrupts mov esp, stack_space ;set stack pointer call k_main hlt ;halt the CPU section .bss resb 8192 ;8KB for stack stack_space: align 4 dd 0x1BADB002 ;magic dd 0x00 ;flags dd - (0x1BADB002 + 0x00) ;checksum. m+f+c should be

Using NASM and TCP Sockets

跟風遠走 提交于 2019-12-11 09:33:56
问题 I am trying to teach myself some NASM x86 assembly using some Unix system calls. I am trying to create a simple TCP server and I have the code working up until the send() command. I can connect via telnet but I get a segfault once my code reaches the point where it tries to send a response to the client. This is the segment of code that is producing a segfault: ; push on to stack for send push dword 0 push dword [start_len] push dword [start] push dword [socket] ; send something back ; THIS

x86 assembly create Win32 executable NASM

。_饼干妹妹 提交于 2019-12-11 09:04:05
问题 I want to create a valid Win32 executable, that can be run as standalone application. For example, this simple program: bits 32 mov eax,1 ret I compiled it using NASM with nasm test.asm -o test.exe Then I ran that program. It started NTVDM and it told me "The NTVDM CPU encountered illegal instruction" and some technical details, probably dump, and registers. So, I want to create a standalone Win32 application in assembly language. I don't want to create COM file, like in DOS. 回答1: [section]

print number to screen assembly

时间秒杀一切 提交于 2019-12-11 08:28:01
问题 I want to print a number in a register to the screen. Furthermore I want to save it as a string of characters (bytes). So if I had a number like 150, I would want to save it at a certain address as '1', '5', '0' mov ebx, dword ptr[ebp+8] ; eax contains value ; ebx contains address to store characters ; here is where conversion would take place Since it's in a register, would you have to convert it to decimal value and then separate each place? 回答1: I´am not sure how to print the ASCII's and

Assembly program that finds second largest value in array

天大地大妈咪最大 提交于 2019-12-11 07:29:09
问题 I wrote a assembly program that finds the max value in an array, but now I would like it to find the second largest number in the array. How would I modify my program to do this? This is the program I wrote and it does work. The program prints all the values in the array and then finds the max value of the array. Now I want it to find the second largest value. %include "io.mac" .STACK 100H .DATA Numbers DW 3,4,5,2,6,0 msg0 db "Printing values in array",0 msg1 db "Max",0 msg2 db "Min",0 .CODE

Printing character from register

一曲冷凌霜 提交于 2019-12-11 07:27:23
问题 I'm using the NASM assembler. The value returned to the eax register is supposed to be a character, when I attempt to print the integer representation its a value that looks like a memory address. I was expecting the decimal representation of the letter. For example, if character 'a' was moved to eax I should see 97 being printed (the decimal representation of 'a'). But this is not the case. section .data int_format db "%d", 0 ;----------------------------------------------------------- mov

x86-64 ELF initial stack layout when calling glibc

人走茶凉 提交于 2019-12-11 07:06:29
问题 Basically, I read through parts of http://www.nasm.us/links/unix64abi and at page 29, it shows the initial process stack of a C program. My question is: I'm trying to interface with glibc from x86-64 nasm and based on what the above shows, argc should be at rsp. So the following code should print argc: [SECTION .data] PrintStr: db "You just entered %d arguments.", 10, 0 [SECTION .bss] [SECTION .text] extern printf global main main: mov rax, 0 ; Required for functions taking in variable no. of