nasm

Reset a string variable to print multitple user inputs in a loop (NASM Assembly)

匆匆过客 提交于 2021-01-29 05:40:09
问题 I'm using a 64 bits Linux system, and I'm trying to use NASM to build a program that asks the user for input, and then prints it. Afterwards, the user can choose to do the same again, or exit. My issue is that the variable 'text', which is used to store the user's input, is not reset at the end of each execution, so something like this happens: User enters text the 1st time: Helloooooooooooooooooooooooooooooo Output: Helloooooooooooooooooooooooooooooo User enters text the 2nd time: Boom!

How to convert ld -Ttext option to a linker script?

一个人想着一个人 提交于 2021-01-29 03:02:58
问题 I've found this tutorial on creating an operating system, and I'm trying to convert the linking part in the make file into a linker script. Here is the tutorial: https://github.com/ghaiklor/ghaiklor-os-gcc Here is the make file: SOURCES = $(shell find cpu drivers include kernel libc -name '*.c') HEADERS = $(shell find cpu drivers include kernel libc -name '*.h') OBJ = ${SOURCES:.c=.o cpu/interrupt.o} ASM = nasm CC = gcc LD = ld -m elf_i386 CFLAGS = -g -ffreestanding -Wall -Wextra -fno

How to convert ld -Ttext option to a linker script?

大城市里の小女人 提交于 2021-01-29 03:02:15
问题 I've found this tutorial on creating an operating system, and I'm trying to convert the linking part in the make file into a linker script. Here is the tutorial: https://github.com/ghaiklor/ghaiklor-os-gcc Here is the make file: SOURCES = $(shell find cpu drivers include kernel libc -name '*.c') HEADERS = $(shell find cpu drivers include kernel libc -name '*.h') OBJ = ${SOURCES:.c=.o cpu/interrupt.o} ASM = nasm CC = gcc LD = ld -m elf_i386 CFLAGS = -g -ffreestanding -Wall -Wextra -fno

Factorial function in x86 NASM assembly goes wrong

会有一股神秘感。 提交于 2021-01-29 01:54:26
问题 I'm learning assembly language using x86 NASM. I wanted to write a simple recursive factorial function to which I am passing one parameter using EAX register. After that, I want to print my result on the screen but nothing happens. After sitting and staring on my computer I don't have any clue what is wrong with my code. Can you guys help newbie with this problem? I know that the prologue and epilogue of factorial funtion is not required due I'm not using stack but for me code is more

Is it possible to output a string to the console in C without including the standard library?

半腔热情 提交于 2021-01-28 21:46:56
问题 I'm trying to get better understanding of how assembly and machine code works. So I'm compiling this simple snipet with gcc : #include <stdio.h> int main(){ printf("Hello World!"); return 0; } But this includes the default library. I would like to output hello world without using printf but by inlining some assembly in the C file, and adding -nostdlib and -nodefaultlibs options to gcc. How can I do that ? I'm using Windows 10 and mingw-w64 with Intel core i7 6700 HQ (laptop processor). Can I

Is it possible to output a string to the console in C without including the standard library?

时光怂恿深爱的人放手 提交于 2021-01-28 21:16:41
问题 I'm trying to get better understanding of how assembly and machine code works. So I'm compiling this simple snipet with gcc : #include <stdio.h> int main(){ printf("Hello World!"); return 0; } But this includes the default library. I would like to output hello world without using printf but by inlining some assembly in the C file, and adding -nostdlib and -nodefaultlibs options to gcc. How can I do that ? I'm using Windows 10 and mingw-w64 with Intel core i7 6700 HQ (laptop processor). Can I

Difference between (sp) and [sp] in assembly

房东的猫 提交于 2021-01-28 11:00:52
问题 I was experimenting with the NASM assembler, when I came across a problem: mov (sp),bx mov [sp],bx The first instruction is assembled properly while the second one is not, and gives me the error: error: invalid effective address Why is this? What's the difference between the two? 回答1: (%sp) would be an AT&T syntax addressing mode. (Invalid because 16-bit addressing modes can't use SP directly, only BP|BX + SI|DI NASM x86 16-bit addressing modes; that's also the reason mov [sp], bx is invalid.

Integer describing number of floating point arguments in xmm registers not passed to rax

安稳与你 提交于 2021-01-28 09:30:59
问题 I have got a function which is declared as follows: double foo(int ** buffer, int size, ...); The function is a part of cpp implementation of a program. I use last parameter to pass multiple double variables to the function. The problem is that on Mac I do not receive valid number in rax register, on the other hand on ubuntu it works as expected. A simple example: CPP #include <iostream> extern "C" double foo(int ** buffer, int buffer_size, ...); int main() { int* buffer [] = {new int(2), new

Why Segment fault when writing to writeable .data section? Using Ubuntu, x86, nasm, gdb, readelf

给你一囗甜甜゛ 提交于 2021-01-28 09:01:13
问题 I'm learning to write a simple shell code using assembly. I get a Segment fault when the mov opcode executes to write over the db data. Why? Any guidance appreciated! Debugging with gdb confirms the data is contiguous with the code at run time and readelf analysis of the program confirms the data segment is writeable. section .text global _start _start: ; The following code calls execve("/bin/sh", argv, envp=0) jmp short two one: pop ebx xor eax, eax mov [ebx+12], eax mov [ebx+7], al mov [ebx

Assembly code do not recognise ? and @data

别来无恙 提交于 2021-01-28 08:04:28
问题 It is my first assembly program. Can anyone please help to make it run successfully. I am seeing below compilation error. Why it do not recognize the ? and @data ? I am trying to swap two variables in assembly. I am executing the following command nasm -f elf swap.asm But I get this error: swap.asm:6: error: symbol `?' undefined swap.asm:12: error: symbol `@data' undefined swap.asm:15: error: invalid combination of opcode and operands swap.asm:21: error: invalid combination of opcode and