Questions tagged [nasm]

1

votes
1

answer
1k

Views

How does this assembly bootloader code work?

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...
Aaron Garton
0

votes
0

answer
17

Views

C getting a raw keypress with no stdlib

I am working an a very basic operating system for a learning experience, and I am trying to start with key presses. I am making a freestanding executable, so no standard library. How would I go about taking input from a keyboard? I have figured out how to print to the screen through video memory. /*...
Eric Shreve
3

votes
0

answer
16

Views

what would be the benefit of moving a register to itself in x86-64

I'm doing a project in x86-64 NASM and came across the instruction: mov rdi, rdi I have searched all over but can't find mention of why this would be needed. Does it affect the flags or is it something clever that I don't understand? To give some context its present in a loop right before the same...
nrmad
0

votes
0

answer
7

Views

Trying to print asteric triangle using nested loop in assembly

I am new at writing code in assembly language. But my code doesn't work. Here is my code: section .text global _start _start : mov eax, 3 mov ebx, 0 mov ecx, num2 mov edx, 2 int 80h mov ecx,1 l1 : cmp ecx,[num2] jg _exit push ecx l2: cmp ecx,0 je _exitloop push ecx mov edx,...
Nadia Motalib
1

votes
1

answer
534

Views

FInding length of String in NASM

I'm trying to check the length of a sting given in the program argument as part of a larger program. I need to place the value of the string length in a variable called n, which I've left uninitialized in BSS. I've tried a couple different methods of doing this, including the one Im trying right now...
Matt Kowalczykowski
1

votes
1

answer
237

Views

Change color of console text

I am trying to create a drawing program that displays a block character (ASCII 219) at the current cursor location. The up, down, left, and right keys are used to navigate on the screen. F1, F2, F3, and F4 are suppose to change the color. The escape key quits the program. When using the function key...
Milo
1

votes
1

answer
515

Views

Shellcode with restrictions

For a task I need to create simple shellcode, but it is not allowed that it contains \x80. Notice: To make a system call on linux, like write or exit, you need among others this line: int 0x80, which in the end will produce shellcode including \x80. Nevertheless I need to make system calls, so my i...
Krupuk
1

votes
1

answer
248

Views

prefetch: EIP [00010000] > CS.limit [0000ffff] during second stage execution

I have created a simple bootloader with a second stage (kernel) loaded in memory at 0x1000:0x0000 which my bootloader starts executing with jmp 0x1000:0000. My bootloader is based upon the one in this StackOverflow question My second stage/kernel is a simple command system. The command system has o...
RainingComputers
1

votes
1

answer
244

Views

Nasm ReadConsoleInput

I'm currently working on a simple I/O console application compiled from nasm, but even though it compiles and links, it crashes when I run it. Here's the code: STD_OUTPUT_HANDLE equ -11 STD_INPUT_HANDLE equ -10 NULL equ 0 global start extern ExitProcess, GetStdHandle, WriteConsol...
thomw2o0o
1

votes
1

answer
3.4k

Views

Differences between MOV, LEA and OFFSET

Sure MOV 'moves' (copies actually) something, but how ? Does it put the actual value from the source into the destination or puts some kind of address. This question came to me when I saw in Jeff Duntemann introductive assembly book that he is using interrupt 80h of Linux like this: mov eax,4 ; S...
Paul
1

votes
1

answer
613

Views

Converting from TASM to NASM

I'm very new to assembly. I'm trying to rewrite code from tasm to nasm. Is it very complicated? Code isn't long, about 200 lines. Will you suggest some useful links like http://left404.com/2011/01/04/converting-x86-assembly-from-masm-to-nasm-3/? Or help please help with converting: .model small ;;...
Vitali Kuzmin
1

votes
1

answer
569

Views

Unable to do overlap block transfer in Assembly

I have made a program in Assembly language(nasm) to do overlap block transfer i.e., if one of my array contains '10, 20, 30, 40, 50'(without quotes) then after overlapping of for example 2 elements my resulting array should contain '10, 20, 10, 20, 30, 40, 50'(without quotes). But my problem is when...
Paras
1

votes
1

answer
49

Views

Why do these two variables sync up in NASM

I am a beginner in NASM and I have encountered something I can not understand. Given this code: global main extern printf section .text main: mov qword [VAR_0], 1 ; Init first variable mov qword [VAR_1], 2 ; Init second variable mov rdi, format ; Print first variable -> outputs 2 mov...
Mörkö
1

votes
2

answer
906

Views

How to take a string as a input in Assembly x64

I am writing a program to check if a string is Palindrome or not. I want to take a string as input from user. The string can contain any character ranging from digits to special characters. How can I take input from user. I have tried the following code. global _start section .bss string resb 9 sect...
Paras
1

votes
1

answer
143

Views

How to set color when call printf in assembly

I want to set the color when I call printf from assembly. This is my code: Out: mov rdi, answer mov rsi, r10 mov rax,0 call printf section .data answer: db '\033[0;31m%d\033[0m',10,0 I use NASM to compile and gcc to link nasm -f elf64 '%f' gcc -o %e %e.o However, the out...
CXWorks
1

votes
2

answer
1.1k

Views

x86 NASM Indirect Far Jump In Real Mode

I have been messing around with a multi-stage bootloader and I have got all of my code to work, except for the last part: The Jump. I have gotten this code to work out before now but I wanted to make it more modular by replacing this line: jmp 0x7E0:0 With this one: jmp far [Stage2Read + SectorRead...
Jerfov2
1

votes
1

answer
550

Views

Assembly - Unable to set breakpoints lldb

I assembled with these options nasm -O0 -g -f macho64 but lldb complains of 'Unable to resolve breakpoint to any actual locations.' when i try to set any breakpoints at line numbers in the file. I've started trying to learn 64 bit assembly for OS X but it's proving a real challenge so far, there see...
zMesh
1

votes
1

answer
634

Views

Why does printf overwrite the ECX register?

I know printf returns the number of characters printed in EAX. Why is printf changing register ECX to 0? My code snippet: push eax push intFormat call printf add esp,8 I'm running my code on a 64-bit Linux distribution.
neileap
1

votes
1

answer
215

Views

Segmentation fault in x86 while computing floating point sequence

Assembly program to compute sum of given sequence: 1+(1/1!)+(1/2!)+...+(1/10!) using floating point registers. Why do I get a segmentation fault(Core dumped) error in the following program? global main main: mov eax,2 mov ebx, 2 mov edx, 2 .fact: fld dword [ecx] fmul dword [ebx] fstp dword [ecx] fl...
Saumya Sahay
1

votes
1

answer
41

Views

Assemble with nasm including only referenced blocks of code/data

In writing some simple libraries for nasm, I noticed that labels that aren't actually called or referenced are still included in the binary. Is there any way avoid including unused labels and their corresponding code in the object when building / compiling / assembling with nasm?
Fluffy
1

votes
1

answer
117

Views

nasm macro doesn't work properly

I'm trying to set up the IDT of my kernel but I'm getting this linking error: bin/obj/idt.o: In function `setup_idt': idt.c:(.text+0x9b): undefined reference to `interrupt_handler_1' The error says that interrupt_handler_1 isn't defined but it is a macro in interrupt_manager.asm: %macro no_error_cod...
1

votes
2

answer
496

Views

Printing `argv[]` with nasm

I'm trying to print the command line arguments given to my program, using nasm: GLOBAL main EXTERN printf section .rodata fmt db 'Argument: %s', 10, 0 section .text main: push ebp ; push ebp0 mov ebp, esp ; [ebp1] == ebp0 push dword[ebp+8] ; push argc call...
csTroubled
1

votes
1

answer
251

Views

Nasm Dwarf Error Bad Offset

I have a simple Hello World program for Windows in pure x86 assembly code that I have compiled and linked with nasm and ld. The problem I am running into is that I can't get DWARF debugging to work. I am using gdb from Mingw64 (i686-posix-dwarf-rev1). This same problem happens if I use gcc to link i...
SeanRamey
1

votes
1

answer
337

Views

Message while debugging using gdb: Single stepping until exit from function _start

I am writing assembly language program using nasm on linux. The problem is during debugging using gdb it does not step inside the _start function and gives the message 'Single stepping until exit from function _start,' Also, when I set break points after line 1 it says: (gdb) break 2 Note: breakp...
user2277648
1

votes
1

answer
492

Views

Assembly Power(A,b) function

I'm trying to make an assembly power(a, b) function, based on this c code: int power(int x, int y) { int z; z = 1; while (y > 0) { if ((y % 2) == 1) { y = y - 1; z = z * x; } else { y = y / 2; x = x * x; } } return z; } Though, for some reason, it only gets some outputs right, and I can't figure out...
1

votes
2

answer
324

Views

assembly intel x86 call function with local variables

I'm having an issue with a binary search implementation. Note, I do not want to modify this c code, I'm trying to translate it to assembly. Here's my c code: int binary_search_c(int n, int list[], int low, int high) { int middle; if (low > high) return -1; middle = (low + high)/2; if (n == list[midd...
1

votes
2

answer
1.2k

Views

How can I move two dword into one qword?

I found similiar anwser here, but it works only for 32bit. How can I do it in NASM in 64bit processor?
Nominalista
1

votes
1

answer
125

Views

Assembly: trying to write to file, but text is appending to filename

I'm trying to study assembly, while trying out the example in the tutorials I get stuck. I am compiling this using an ubuntu virtual machine. Here is the code: SYS_READ equ 3 SYS_WRITE equ 4 SYS_OPEN equ 5 SYS_CLOSE equ 6 SYS_CREATE equ 8 SYS_EXIT equ 1 section .text global _start _start: mov eax, S...
Dominick Navarro
1

votes
1

answer
1.1k

Views

What does *%gs:0x10 do in assembler?

What does following syntax do in GASM? *%gs:0x10 I know that call *%gs:0x10 call will __kernel_vsyscall, but i don't know what *%register:value do. It's NASM equivalent looks like this: call DWORD PTR gs:0x10
user7428910
1

votes
1

answer
259

Views

Nasm dotted labels

I am familiar with TASM but less with NASM. I have read that NASM allows for local labels, which are indicated with a dot before the name. For instance, the code .loop: ;some code jmp .loop define a local label whose name is .loop, and the referenced address is used in the later instruction jmp. How...
Nicola
1

votes
1

answer
412

Views

16 bit animation - getting started

Took a while but finally got to square 1 in 16 bit graphics. Here I clear the screen and draw a single pixel: mov ax, 0a000h mov es, ax ; es - Extra Segment now points to the VGA location mov ax, 0013h int 10h xor al, al mov dx, 3c8h out dx, al inc dx mov al, 63 out dx, al out dx, al out dx, al...
DillingerLee
1

votes
1

answer
71

Views

Assembly number change error

I tried to make a assembly program that took one number, and then printed it. But when I wrote 1, it wrote 4171. Why, and how can I fix it? I am using 64 bit assembly, I assembled it with nasm -f macho64 scanf.asm, and I linked it with gcc -o scanf scanf.o -Wl,-no-pie. And I've tried to use square b...
SpilledMango
1

votes
1

answer
175

Views

Dos Assembly Program hanging during Interrupt

The following program assembles without error or warning. However, when I run it it displays 'ABK' on the top and then hangs the DosBox. I am using nasm assembler and DosBox. I write nasm eex9_2.asm -o eex9_2.com [org 0x100] jmp start oldisr: dd 0 kbisr: push ax push es mov ax, 0xb800 mov es, ax x...
AhmedBilal
1

votes
2

answer
1.4k

Views

GDB Debugger: An internal issue to GDB has been detected

I'm new to GNU Debugger. I've been playing around with it, debugging Assembly Files (x86_64 Linux) for a day or so and just a few hours ago I ''discovered'' the TUI interface. My first attempt using the TUI interface was to see the register changes as I execute each line at a time of a simple Hello...
Jazz
1

votes
1

answer
346

Views

String to integer in assembly

I want to transfer string to integer for example, when I type 1234 in string, it will transfer to integer 1234. However, when I type 1234, only 12 comes out as a result and I have no idea what the problem. %include 'asm_io.inc' segment .bss string resb 32 segment .text global main main: enter 0...
Changhun Lee
1

votes
1

answer
45

Views

My assembler doesn't seem to output 32-bit code

This is an example of the behavior I ran into. When assembling the following program: [BITS 32] mov eax, 0x1234 Using: nasm -f bin in.asm -o out.bin I get the following binary output: B8 34 12 00 00 B8 is opcode for 'move into eax' and it should take a 32-bit value and put it in there (i.e. should j...
almosnow
1

votes
1

answer
6.2k

Views

How to print the length of a string in assembly

I am learning assembly using the following hello world program section .text global _start ;must be declared for linker (ld) _start: ;tells linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4...
1

votes
1

answer
62

Views

Wrong result after multiple read

I was wondering i someone could help me with my code, i want to read more than one time from the stdin in x86 but when i read the second time, it is ignoring the number and just add the 50. I want it to work so that i can call it as many times as i need to go adding the register EAX by an arbitrary...
coolzoa
1

votes
2

answer
68

Views

Compiling assembly program to flat-form binary includes extraneous 'f' chars that don't exist in other formats

I'm working on a program written in assembly: xor eax, eax ; make eax equal to 0 push eax ; pushes null push 0x68732f2f ; pushes /sh (//) push 0x6e69622f ; pushes /bin mov ebx, esp ; passes the first argument push eax ; empty third argument mov edx, esp...
jakenberg
1

votes
1

answer
192

Views

NASM mixed string in output

I'm trying to make a simple 'create file with prompt' code from the tutorial I fetched here Assembly - File Management. But everytime I input something, the output strings in the terminal will be mixed and cut together. And the file that would be created is mixed too. Code is here: section .data Ms...
Miretazam Ciptaprima

View additional questions