FAQ Database Discussion Community


x86 assembly code not compiling

assembly,x86,nasm
I have the following code in which I am trying to call an assembly function in C, which is trying to print "e" on the VGA Display (of QEmu): void main() { extern void put_in_mem(); char c = 'e'; put_in_mem(c, 0xA0); } The function put_in_mem is defined below: .global _put_in_mem...

How to identify the calling conventions within assembly code

assembly,nasm,calling-convention
I have got three assembler code fragments and I should identify the proper calling convention (CDECL, STDCALL, FASTCALL) for each fragment. In order to identify the calling convention I was searching for the stack cleaner which is either caller or callee. But what if I cannot find the cleaning code...

NASM 64-bit OS X Inputted String Overwriting Bytes of Existing Value

osx,assembly,x86,nasm,x86-64
I am trying to write a simple assembly program to add two numbers together. I want the user to be able to enter the values. The problem I am encountering is that when I display a string message and then read a value in, the next time the string is...

Assembly variable assignment

linux,assembly,nasm
I'm reading Assembly Language Step by Step Programming with Linux by Jeff Duntemann. In the book he mentioned that the code EatMsg: db "Eat at Joe's",10 mov ecx,EatMsg Copies not the content of EatMsg but the memory where the content is stored at. This is understood and I have confirmed...

NASM - When to use capitalized letters

assembly,nasm
I am trying to learn NASM, and I have checked a few tutorials. But some tutorials said that you should write 'mov' while some others said 'MOV' and so on ('int' and 'INT'. Is there a difference?

puts implementation in assembly with nasm x86-64

assembly,nasm,x86-64,puts
I'm new to assembly and I'm trying to work on an implementation of the C function puts in assembly with nasm x86-64 on my Ubuntu. Everything was fine until I write the tests for the function: there is a behavior that I can not reproduce: When I send char *str...

Reversing order of a string in ASM (NASM)

assembly,x86,nasm
Having trouble getting this to reverse the order of the characters of a string, it works with integers but not strings. It is outputting everything including the string until I "reverse" it. Then it just outputs a blank line... instead of outputting the string in reverse order. I think something...

Understanding NASM Macro

assembly,macros,ffmpeg,nasm
I've come around this macro in a assembly source file and I just can't figure out how it's working. So first I come around this function (hevc_deblock.h): cglobal hevc_v_loop_filter_chroma_8, 3, 5, 7, pix, stride, tc, pix0, r3stride sub pixq, 2 lea r3strideq, [3*strideq] mov pix0q, pixq add pixq, r3strideq TRANSPOSE4x8B_LOAD...

Assembly coding strdup. Malloc calling in shared library

assembly,shared-libraries,nasm,x86-64
I have a problem, I can't compile my strdup while calling malloc. When I don't call malloc, it compiles my shared library perfectly, so if someone could help me that would be great ! here is my code: BITS 64 DEFAULT REL global my_strdup:function extern malloc my_strdup: [...] call malloc...

Assembler plump/water animation

assembly,nasm,interrupt,ms-dos
I am new in assembler and I am looking for easy solution how to insert a loop in my code. Can you guys give me a tip or answer? I found some articles on google and I cannot understand them cuz I am dumb, though. I've to do a projeckt:...

NASM Assembly while loop counter

c,loops,gcc,assembly,nasm
I'm writing a while loop in assembly to compile in the Linux terminal with nasm and gcc. The program compares x and y until y >= x and reports number of loops at the end. Here's the code: segment .data out1 db "It took ", 10, 0 out2 db "iterations...

Garbage in string output function

linux,assembly,nasm
I'm trying to write a printf replacement in asm and so far have this code: ; string is loaded into r8 print_string: push rax push rbx push rsi push rdx ; load string pointer into ecx mov rsi, r8 ; loop over every char print_string_loop0: cmp sil, 0 ; stop...

Nasm, not printing the correct value

c,assembly,floating-point,printf,nasm
I've made a nasm procedure that calculates the eucledian distance between two vectors of a certain size. This nasm function is called from a C file which get the result of the function. I've tested, and it works, the value returned is correct, I can print it withoud any problem....

nasm is not executing file in Windows 8

windows,assembly,windows-8.1,nasm
Recently started learning Assembly so I'm relatively new to this. We use Linux back at school but I wanted to try coding on my PC. I'm using nasm on a Win8.1 64-bit system. Here's the code: section .text global [email protected] [email protected]: mov edx, len mov ecx, msg mov ebx, 1...

VT-100 commands are working strangely

linux,nasm,syscall,vt100
I'm writing simple clock program with NASM. I'm using Ubuntu 14.10 Vagrant box under OSX via iTerm. Terminal is xterm, so should be VT-100 compatible. I need to remove one line. For instance, I expect the following behaviour: Hello, this is clock program 13:01:25 UTC+4 Next moment: Hello, this is...

What's the asm equivalent of replacing a char from a string to a char of another string?

assembly,nasm,x86-64
I'm trying to code strcat to learn assembly. I code on mac osx with nasm using 64 bit assembly, with Intel syntax. Here's my result so far : section .text global _ft_strcat _ft_strcat: mov rax, rdi mov rbx, rsi loop_s1: cmp byte[rax], 0 jz copy_str inc rax jmp loop_s1 copy_str:...

How do you round quotients when dividing in nasm?

assembly,decimal,nasm,divide
im not sure if m using the wrong data types or the wrong instruction or what but div,idiv,fdiv all seem to give me a 0 for the quotient. And i want to get some decimal number rounded to a couple decimal places. i think im using the correct registers for...

NASM Assembly mathematical logic

c,gcc,assembly,logic,nasm
I have a program in assembly for the Linux terminal that's supposed to work through a series of mathematical manipulations, compare the final value to 20, and then using if logic, report <, > or = relationship. Code is: segment .data out_less db "Z is less than 20.", 10, 0...

GNU GAS: Label is not relatively referenced

assembly,linker,nasm,boot,gas
I am writing a little bootsector for learning purpose. Here is boot.S .code16 .text movw $0xB800, %ax /* 0xB000 is the text screen video memory */ movw %ax, %es /* set it as the %es segment */ movb label, %al movb %al, %es:0x0 /* screen[0] = 'A' */ movb $0x07,...

NASM Difference between CMP and OR

assembly,nasm
I got 2 questions. The first one: what is the difference between 'or' and 'cmp'? I have seen both, and it seems like they do the same thing. My second question: what does or al, al mean? Should it not return true all the time (like x == x)?...

doubly linked list in nasm assembly

assembly,x86,nasm
I wanted to do a double linked list in Nasm . I have this structure for Node struc node left: resd 0 right: resd 0 data: resd 0 endstruc I do this when i want to use malloc push dword [node_sz] call [malloc] add esp, 4 * 1 Where: node_sz...

Printing an entire array on a single line using printf asm nasm

arrays,assembly,syntax,printf,nasm
I am using NASM for compiling my ASM program and I am having trouble figuring out how to print an entire array on a single line (without necessarily knowing how big the array is) using a loop. Whenever I create a loop with printf it prints the values on multiple...

Assembly execve failure -14

linux,assembly,nasm,elf,syscall
Program writes executable placed in it's second segment on disk, decrypts it(into /tmp/decbd), and executes(as it was planned) file decbd appears on disk, and can be executed via shell, last execve call return eax=-14, and after end of the program, execution flows on data and gets segfault. http://pastebin.com/KywXTB0X In second...

Faulty compilation of string constant in ASM

assembly,cygwin,nasm
I'm writing a program to get the hashes of certain function-names in ASM. The function to fetch the string constants is the following: get_strings: call get_curr_addr pop esi add esi, 9 jmp str_return db "LoadLibraryA" db 0x00 This produces the following string constant in the bytecode (xxd output): ... 00000040:...

lodsb instruction causes a stack overflow

nasm,shellcode
I want to search for a pattern in memory of current process. I query for memory pages using VirtualQuery to extract ranges of interest. The problem is that after 5 minutes of continous looping the program crashes by a stackoverflow. The size of allocated memory by the process gets bigger....

C float in NASM x86 assembly

c,assembly,x86,nasm
In my university project i have to use binary representation of float number in x86 assembly for arithmetic operations. Using FPU is forbidden so i try to read float number and return it as DWORD but whatever i try to do i get "-nan". Any advices? Edit: I use gcc...

NASM says “Invalid combination of opcode and operands”

assembly,nasm,opcode,operands
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...

getting character from string and using it as array index… ASM

arrays,assembly,printf,character,nasm
Having trouble using a string array and getting each character from it and adding a 1 to a frequency table of the corresponding ascii index (frequency table is indexed by ascii value): Example, get character 'a' then add 1 to the frequency table of index of the array ['a']. I...

`mov` a literal to the ES register

assembly,x86,nasm
I have this portion of code : mov ax, 0x100 mov es, ax but when I try to replace the code above by this : mov es, 0x100 nasm tells me that I made an invalid combination of opcode and operands. Why ?...

NASM output prompt for user input

assembly,x86,nasm,dosbox
Related, but not helpful to my current situation: nasm dos interrupt (output string) (I just wanted to clarify this is not a duplicate) What I am trying to do is create a prompt that will say "Enter a Base 10 number: " to the user. After that, I will convert...

NASM add byte to register ebx

assembly,x86,nasm
Is there a simple way to make this NASM snippet to work? add ebx, byte [ebp-10+ecx] I get the following error: error: mismatch in operand sizes. I want to add the byte in the memory address [ebp-10+ecx] to the least significant byte of ebx. Of course ebx is a 4...

BIOS Real Mode Alert NASM

assembly,nasm,bios
Is it possible to create an alert sound (like '\a' in C) using BIOS interrupts with assembly? If so, how can I do it? I have tried to print \a, but that did not work as intended.

Why does nasm say “invalid combination of opcode and oprands”?

assembly,x86,nasm
I'm trying to assemble a certain file of code in which nasm points to a line (shown below) and says "invalid combination of opcode and oprands". I have no idea what's wrong with the line. out edx,ecx The line of code sends the address in ecx to port 0xCF8 -...

NASM assembled bootloader memory issue

assembly,nasm,bootloader
I am writing a bootloader with nasm. At the moment it is designed to output a welcome string, then record keystrokes while displaying them, printing the stored keystrokes upon finding the enter key, and finally halting. bits 16 org 0x7C00 start: jmp main bgetkey: pusha mov ax, 0 mov ah,...

NASM: copying a pointer from a register to a buffer in .data

linux,assembly,nasm,x86-64
I am new to asm. I am trying to copy a pointer from a register to a .data variable using NASM, on linux 64-bit. Concider this program: section .data ptr: dq 0 section .text global _start _start: mov [ptr], rsp mov rax, 60 mov rdi, 0 syscall Here I try...

JMP instruction in NASM gives segmentation fault

assembly,nasm
This is my code to concatenate two strings in NASM. I got a segmentation fault core dumped error. So i started commenting to find the source of the error. As you can see in the code I used %ifdef and %endif to create block of comment. When I excluded the...

What does a CALL to an address in the .rodata segment do?

assembly,nasm
I have some assembler code here (32-bit, Linux, NASM), and in it, I assume, there is a call into an address which is part of the .rodata segment. I couldn't find information about what this does exactly, or maybe I just interpreted the code wrong. 60000f7: mov edx, 0x2 60000fc:...

Injected 64 bit shellcode wont execute syscall

c,gcc,assembly,nasm,shellcode
I am currently trying to inject code that will print helloworld into a vulnerable program. I have succeeded in injecting the code by storing it in one of the environment variables and overwriting the rip register to point to that code. Here is my assembly and op codes: 0000000000000000 <_start>:...

MinGW's ld cannot perform PE operations on non PE output file

gcc,assembly,mingw,nasm,osdev
I know there are some other similar questions about this out there, be it StackOverflow or not. I've researched a lot for this, and still didn't find a single solution. I'm doing an operative system as a side project. I've been doing all in Assembly, but now I wanna join...

NASM: in/out instead of int

assembly,nasm
When writing a bootloader how do you make calls to ports instead the use of interrupts (i.e. int 10h)? Is there a list someplace online I am unaware of for known vectors? Is there a place I can go to do mapping of hardware not covered by the bios interrupts...

Calculating average of floats rounded to an integer NASM

arrays,assembly,floating-point,average,nasm
Basically the program is suppose to input floating point numbers from the user, then get the sum of them, the average of them (from 0.0 to 100.0), anything above is not counted and anything below isn't counted as well. A negative number will not just not be counted but also...

Print floats in nasm without binding to C functions

linux,assembly,nasm,syscall
I'm wondering, how to print float numbers in nasm using only syscalls in linux. I have the following code, but it prints only @ section .data num dq 2.0 len equ $ - num section .text global _start _start: mov edx, len mov ecx, num mov ebx, 1 mov eax,...

x86 assembly: Understanding db syntax

assembly,x86,nasm,bootloader,16-bit
I've just started learning x86 assembly by following along with a online book that I found: http://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf As I was going through the book and following the examples, I ran into a problem that I couldn't solve due to my own ignorance of assembly, or maybe programming in general. I...

NASM - Get number of items in stack

assembly,nasm
I am trying to figure out how to get the number of items in the stack by subtracting the sp register with bp. What am I doing wrong? I get totally wrong result MOV bp, 0x7E00 MOV sp, bp PUSH 'A' PUSH 'B' PUSH 'C' POP bx MOV al, bl...

Hello World program in Nasm x86-64 prints Hello World continuously

assembly,nasm
Could you please help me on this code. On execution, the program prints Hello World continuously and does not exit. I want to use this code as shellcode in C program too, hence I have not defined Hello String in data section. Please let me know where is the issue....

NASM - Variable Basics

assembly,nasm
I know that you can create a string in nasm by writing this: mystring db 'Hello World' But if I want to move a single character, let's say e, the second character in the string to the al register. How can I do that? Should I write mov al, mystring+1...

Assembly shift right with carry in?

nasm
My class is using Nasm assembly and I was trying to figure out different ways to shift, we know the instructions shr/sar, shl/sal, ror, rcr, rol, rcl. But would I shift right and set the leftmost bit to whatever I want. For example: I have 11010011, and shifting right would...

NASM Reverse an integer array

arrays,assembly,x86,stack,nasm
Conceptually, I'm trying to push the values onto the stack and pop them off in "opposite" order. In practice, I think I'm doing that but I'm not sure. The array I'm passing is defined in the section .data as array: dd 1, 2, 3, 4, 5, 6 and the size...

Storing variables in specific addresses in assembly language

assembly,x86,nasm,memory-address
I have an assignment that asks me to make a Fibonacci loop and store the first 10 numbers in the memory from address 200 hexadecimal and so forth. I am using DOSBox 0.74 for this. I know how to do the Fibonacci loop I just don't get how I can...

Floating Point always returns 0

assembly,floating-point,nasm
I'm trying to wrestle with floating points in NASM, and I just can't seem to figure out what I am doing wrong. This program always gives me back 0.000000, and I really can't see where an error could be. extern printf extern scanf SECTION .data junk: dq 7.6 temp: dq...

accept() doesn't block the program execution

linux,assembly,x86,nasm
I'm starting to program network programs in asm (NASM) and technically, the accept function block the program (passive socket). Well, in my program I execute the program and the program finish. I've tested setting the backlog to 1 (listen function), but it's not the problem... What happen? BITS 32 section...

Is this an overflow, or maybe more keyboard data?

assembly,nasm,bootloader
I am writing a bootloader, and it's functionality is basically limited to printing a string, then copying keyboard characters to the screen as they are typed. While writing the routines that read and write the key, I noticed my print routine was not detecting the null terminator in offset (plus)...

Print a number in NASM - building an x86 Bootsector

assembly,nasm
I just started messing around with assembly language and I tried to print the number 9 on console. Here is what I wrote: global _main section .data digit equ 9 section .bss section .text _main: mov edx, 1 mov ecx, digit add ecx, 48 mov ebx, 1 mov eax, 4...

Packed masking in SSE

c,assembly,x86,nasm,sse
I need to build some kind of masking system for a packed single because I need to use packed operations on vectors that contain less than 4 elements. So, for example, I need to do something like this: section .data align 16 a: dd 1.5, 2.3, 5.0 align 16 x:...

C printf function does not work properly in NASM assembly

c,assembly,nasm
I'm trying to use a printTime() function written in C to test the running time of my 32 bits NASM program. void printTime(float time){ printf("The cpu time is %e \n" , time); } Here is part of the NASM code: push edi <---------------- Here edi holds int 6580001 call printTime...

NASM: Makefile for library

assembly,makefile,nasm
I'm having trouble building a makefile for a library in nasm, since it requires that you run nasm with one input file at a time. I have tried with the %.o : %.s thing but I'm probably doing it incorrectly since it's not working. Here is what I have: NAME...

this code to find the largest element in an array in nasm does not work

assembly,nasm
section .bss digit0: resb 2 digit1: resb 1 answer1 : resb 1 answer2 : resb 1 answer : resw 1 array: resb 50 element: resb 1 num: resb 1 temp: resb 1 largest: resb 1 smallest: resb 1 count: resb 1 section .data msg1: db "Enter the number of elements...

nasm: jump when input is NULL

c,assembly,nasm,libc
I am recoding puts using nasm (64bit), and when puts receives NULL as argument it prints (null). I'm trying to recreate that behaviour, except I can't get the code to jump to the part where it prints (null). Instead it just prints nothing here's my code: global _my_puts section .text...