Questions tagged [nasm]

1

votes
1

answer
38

Views

NASM automatically escaping shellcode initialized in .data [duplicate]

This question already has an answer here: Assembly: printf not printing new line 2 answers I am attempting to write a piece of assembly code which will perform operations on some shell code I have initialized in .data My initialization is as as follows: section .data shellcode: db '\x31\xc9\xf7\xe1...
Hosty
1

votes
1

answer
3.1k

Views

Declaring variables in NASM

I am just learning NASM and I am kind of struggling to figure this out. How do you declare variables in NASM? For example, how would you declare unsigned int i in NASM? Thanks
Kenneth
1

votes
2

answer
1.3k

Views

Wait for keypress Assembly NASM, Linux

I'm working on a Hello World in Assembly for x86-64. I have managed to create one that finishes when Enter key is pressed, but I have to finish it when ANY key is pressed. This is the code for waiting the ENTER Key: mov rax, 0 mov rdi, 0 mov rdx, 1 syscall I can't use any int xh or something like t...
Guolf3377
1

votes
1

answer
304

Views

Is it good or bad to use BIOS interrupts for protected mode?

I have made a very basic boot loader based on MikeOS boot loader ( Link ). I'm using NASM and QEMU for assembling and testing. And I'm trying to enable protected mode for my OS. So, I started searching web for more details and to know more about BIOS interrupts. I came across wikipedia and read an a...
1

votes
2

answer
64

Views

How can I compare the first character of a string with another character in x86-64 assembly?

I have an initialized string 'Hello, World!' from which I would like to extract the first character (i.e. 'H') and comapre it a character that is passed into a register at run time. I have tried comparing the first character of 'Hello, World!' with 'H' through the following code: global start sectio...
mooncow
1

votes
2

answer
76

Views

NASM floating point - invalid combination of opcode and operands

I am trying to compile the following code sample (NASM syntax) from this article on x86 assembly floating point: ;; c^2 = a^2 + b^2 - cos(C)*2*a*b ;; C is stored in ang global _start section .data a: dq 4.56 ;length of side a b: dq 7.89 ;length of side b ang: dq 1.5 ;opposite angle to side c (a...
Jet Blue
1

votes
0

answer
45

Views

Loop exiting early when making Linux system calls [duplicate]

This question already has an answer here: Why do x86-64 Linux system calls modify RCX, and what does the value mean? 1 answer What are the calling conventions for UNIX & Linux system calls on i386 and x86-64 4 answers I am trying to write a program that prints an integer, the integer is stored in...
うちわ 密か
1

votes
0

answer
74

Views

Getting crazy results in Assembly

I am having to write a simple program in assembly that takes an N number inputs as ints, and finds the average of them all added together. As the tittle suggests, I am getting crazy numbers for answers. Here is the code that I have written. %include 'along32.inc' section .data intA dq 0; Holds the i...
killer3p0
1

votes
0

answer
313

Views

echo client in assembly

I am learning some assembly language. And in the process of doing that I am trying to write up a echo client / server with TCP sockets in nasm assembly. I have done socket programming in various other languages such as C and java, and am trying to make it work in assembly. I have found a couple exam...
user695752
1

votes
0

answer
113

Views

Pushing imm32 ends up in pushing imm64? [duplicate]

This question already has an answer here: How many bytes does the push instruction push onto the stack when I don't specify the operand size? 2 answers push on 64bit intel osx 4 answers From the intel instruction reference: 68 id PUSH imm32 It means pushing dword-sized immediates is valid in 64-bi...
St.Antario
1

votes
0

answer
64

Views

linking functions in shared object - ld

I'm trying to write a library (shared object) in assembly. I'm compiling with nasm and linking with ld. I've got 2 ASM files containing differents symbols. I'm trying to call a symbol contained in the first file from the second one, but ld keep throwing an error : relocation R_X86_64_PC32 against sy...
Nathan Schwarz
1

votes
1

answer
530

Views

Adding 2 inputted numbers in Assembly using NASM

I have done my best to explain all of my thought process when adding these two numbers. However, upon running the resulting executable I end up with 'Sum is: j' which is clearly wrong. Additionally, it seems that no matter which inputs I give the sum stays as 'j' so there must be something awfully...
raka
1

votes
0

answer
58

Views

Capture keyboard input in a persistent program

I am trying to create a simple 'cheating' program for old dos games that would work by loading itself into memory, then intercept keyboard input and do something when a certain key is pressed. So I capture the input by cli mov ax, [es:9*4+2] mov [origseg], ax mov ax, [es...
Jakub Judas
1

votes
0

answer
216

Views

Array input using scanf in nasm

I'm trying to read floating point input for array using loop and then printing the array. After reading n values, it gives segmentation fault. I can't figure out what is wrong. How can i correct the error? %macro exit 0 mov rax,60 mov rdi,0 syscall %endmacro extern printf extern scanf ;------------...
welkin
1

votes
1

answer
101

Views

OS development : switching to 32bit mode breaks my code

EDIT: My problem solved when I move everything after BITS 32 to disk_double_error but now it is still broken yesy it displays the message but then when i hit Y it just restarts/reboots the system What may be the reason for that ? (sry for bad english) Hello I am trying to write a simple os just for...
Programmer
1

votes
0

answer
34

Views

Random output in assembly program. Using system calls for OSX

I've searched around and I haven't found anything. The code is as follows: hello_world db 'Hello World!',10 .hellolen equ $ - hello_world get_input db 'Enter a number: ',10 .getlen equ $ - get_input input times 10 db 0 .len equ $ -...
Brendan Lane
1

votes
1

answer
50

Views

error: invalid combination of opcode and operands

I am new to NASM. I am getting the error: invalid combination of opcode and operands on the first line below mov si,bl ;si contains address of number string mov cx,7 ;once for each line jmp print_num ;print the number loop line_loop ;decrement cx, repeat if cx0 int 20h
Sam M
1

votes
0

answer
49

Views

Why is this x86 assembly program segfaulting?

I'm using the NASM x86 assembler with the ld linker, assembling to Mach-O format on MacOS. I gave myself a challenge of writing a program that draws a box in the terminal, the challenge being that I would try to implement the exact same program with as close to the exact same behavior as possible i...
Shoblade X
0

votes
1

answer
102

Views

Why doesn't NASM have trouble with valid instruction mnemonics as symbol names in operands?

I wrote the following simple program, but nasm refuses to compile it. section .text global _start _start: mov rax, 0x01 mov rdi, 0x01 mov rsi, str mov rdx, 0x03 syscall mov rax, 60 syscall segment .data str db 'Some string' nasm -f elf64 main.asm main.asm:15: error: comma, colon, decorator or end o...
St.Antario
1

votes
0

answer
55

Views

What's wrong with my NASM program?

I recently started programming in assembly language and could get something wrong. This code is supposed to write out '21947392': section .data nl db 10 section .bss number resb 19 .end resb 1 section .text GLOBAL start start: mov rdi, 21947392 call _printNumber mov rax, 0x2000001 xor rdi, rdi sysca...
Going To Dark
1

votes
1

answer
48

Views

Boot loader makes different results after lgdt in different virtual machines

I'm writing a simple boot loader. The boot loader is compiled from two assembly files: boot.asm, protected_start.asm. boot.asm loads protected_start to 0x10000, sets GDTR, enters protected mode and jump to 0x10000. So the encoding is set to 16-bit in boot.asm, 32-bit in protected_start.asm. I use QE...
paxbun
1

votes
0

answer
172

Views

Assembly - undefined reference to `[email protected]'

I am a newbie in assembly language, so I've got the following program (test.asm): section .data hello: db 'Hello world!',10 helloLen: equ $-hello section .text global main main: mov eax,4 mov ebx,1 mov ecx,hello mov edx,helloLen int 80h...
1

votes
0

answer
90

Views

Can not find mistake in mandelbrot set code SSE assembly

Im programming mandelbrot set in assembly using SSE. I use interrupt: mov ax,0x4F02 mov bx,0x107 int 0x10 to set video mode to 1280x1024 pixels with 256 colors, then I enable A20 gate and switch correctly to 32 bit protected mode and allow fpu and sse in cr0 and cr4. I tested some simple SSE instruc...
Segy
1

votes
0

answer
67

Views

Using ld to link a file makes it too big for a boot loader, works in nasm though :(

I'm trying to make a simple bootloader, but running into issues with ld (I think). When I compile my assembly file (below) with nasm -f bin, it works and I get a nice 512 byte file. For that one I include org 0x7c00 at the top and everything works as expected. However, now I'm trying to do somethin...
Rogue God
1

votes
0

answer
99

Views

Proper way to print a string without syscall

I want to create a print function i x86 Assembly(NASM)to print a string to the terminal without using any OS(i.e. without any syscall). I wrote the following code so far: main.asm [org 0x7c00] ; load our boot sector here %include 'print_function.asm' ; the print function is declared outside this fil...
bzoark
1

votes
1

answer
218

Views

NASM Modulo operation

I just started assembling with the NASM Assembler. Compiling with gcc using a C-driver. As much as I know, one can implement a modulo function in two ways easily (assuming size_t a in eax, size_t b in ebx for mod(a, b)): first option: minus: sub eax, ebx modulo: CMP eax, ebx JGE minus leave ; else...
1

votes
0

answer
42

Views

Graphics are repeating, assembly boot loader

This code should color the top pixels only red. the pixels keep repeatingly to be colored else where like a tile no matter how much ive changed the line size and the color (I specified only the top 2000 pixels get colored) I think its because of DUBBLE_BUFFER_START's location but I dont know where t...
Dodo
0

votes
0

answer
5

Views

Long jump with a selector decided at run time in x86

I'm trying to perform a long jump in assembly so that I can load a descriptor from the GDT into the segment register CS. I realize I can do this by hard coding the address like this (jmp 0xAB:some_label) but I don't want to hard code the address like that. I see that the jump instruction has the fol...
GamefanA
1

votes
1

answer
86

Views

Unable to read a sector using int13H using custom Bootloader

Recently i was learning x86 assembly and for practice decided to roll up my own Boot loader. Before working with int13H in the bootloader itself i decided to give a try on reading a sector ( logical 19) on floppy disk. But unfortunately after writing down the code and running it on QEMU no data was...
Cosmo Ferrito
1

votes
0

answer
42

Views

NASM unexpected output when printing

I am new have very small problem with assembly NASM in linux. I made simple program for practice that when you put in the text, it adds simple decoration in form of stars. The expected output is: *********EXAMPLE********* instead: *********EXAMPLE ********* here is the complete code of the program (...
thebigcrocc
1

votes
1

answer
34

Views

Entering a non-integer into an unsigned integer using scanf in NASM causing problems in loops

Whenever I try entering a letter or symbol into my scanf for unsigned integers after previously entering an accepted number previously in the loop, it continually enters the previous number, causing the program to run indefinitely. How do I fix this? Here's an example code I wrote: [bits 32] global...
SquidVicious
1

votes
1

answer
58

Views

Adding semicolons to strings in x86 NASM? [duplicate]

This question already has an answer here: What are the calling conventions for UNIX & Linux system calls on i386 and x86-64 4 answers I am trying to make an x86 assembly macro in NASM that uses ANSI escape codes to move the cursor to the specified X Y coordinates in the user's terminal window. The...
SectorSam
1

votes
0

answer
1.3k

Views

Why is “nasm: error: unable to find utility ”nasm“, not a developer tool or in PATH” showing up?

I am trying to learn assembly language for a Macbook Pro on Mac OSX 10.13.6, and I have just downloaded the NASM assembler. I read the manual and it told me to type nasm -h into the Terminal for help I did exactly that, however if I type that command or any other Terminal command which starts with n...
Maldini26
1

votes
0

answer
44

Views

Read content from 0000:FFFF to AX register may change CS:IP to 0xf000:e9df

I want to read memory content located in 0000:FFFF, but when I debug the program, I find that after mov ax, [0xFFFF] . My code : org 07c00h mov ax, 0x0000 mov ds,ax mov ax, [0xFFFF] After running the last code mov ax, [0xFFFF], the CS:IP segment will change to F000:E9DF. So strange....
Jack
1

votes
1

answer
30

Views

Difference in these commands in assembly

What is the difference between mov eax, [esp+0x20] mov ecx, [eax+0x14] and mov ecx, [esp+0x34] I think it is the same, is this right?
H Cook
1

votes
0

answer
46

Views

Message 5 Time repeat?

This is my code with commented explanations: SECTION .data ; Section containing initialised data EatMsg: db 'Eat at Joe's!',10 EatLen: equ $-EatMsg SECTION .bss ; Section containing uninitialized data SECTION .text ; Section containing code global _start...
Hasan Hawar
1

votes
0

answer
26

Views

Convert input string to number NASM Linux x86_64

I'm really new to NASM and I'm trying to convert from string to number in NASM but I don't know if it works. The code compiles without a problem but it's always displaying the same result no matter the numbers Can someone take a look to see if anything is wrong? string_int: xor rbx, rbx ; result sav...
Ratsiev
1

votes
0

answer
76

Views

ld: illegal text-relocation (objects files assembled with nasm)

I am trying to create a dylib from objects file assembled with NASM, but I get the following error: ld: illegal text-relocation to 'newline' in objects/ft_puts.o from '_ft_puts' in objects/ft_puts.o for architecture x86_64 Here is my ft_puts.s: SYS_WRITE equ 0x2000004 STDOUT equ 1 section .da...
Stephane
1

votes
0

answer
51

Views

Unexpected crash on macOS while overriding function return address

I was writing a program which takes many arguments as input parameters. I decided to copy all of them which were passed through registers to stack. To make iteration more consistent I decided to keep function return address in one of registers which wasn't used at time. Whenever I was overriding ret...
Mateusz Stompór
1

votes
1

answer
150

Views

How to get arguments from the command line(assembly nasm ubuntu 32bit)?

I want to 'print' the argument in command line, for example, When i type '$./sum3 10' (at command line), number '10' must be shown next line (like this) $./sum3 10 10 and this is the code. segment .bss p_arv resd 1 segment .text global main main: enter 0,0 pusha mov eax, dword [ebp+12...
Forestellar

View additional questions