nasm

“Hello World” function without using C printf

时光毁灭记忆、已成空白 提交于 2020-01-01 05:47:06
问题 UPDATED It's my second day working with NASM . After thoroughly understanding this section .programFlow global _start _start: mov edx,len mov ecx,msg mov ebx,0x1 ;select STDOUT stream mov eax,0x4 ;select SYS_WRITE call int 0x80 ;invoke SYS_WRITE mov ebx,0x0 ;select EXIT_CODE_0 mov eax,0x1 ;select SYS_EXIT call int 0x80 ;invoke SYS_EXIT section .programData msg: db "Hello World!",0xa len: equ $ - msg I wanted to wrap this stuff inside an assembly function. All (or most of) the examples on the

Output Data Register value in NASM

心不动则不痛 提交于 2020-01-01 05:29:26
问题 new guy here, and already I have a question. I'm adapting example code used in Jeff Duntemann's assembly books, and I want to print out an integer value stored in a data register to terminal? What the following code below does is that it prints out the strings okay, pushes value in ECX okay, but when it gets to the following: pop ecx mov eax,4 mov ebx,1 mov edx, ecx int 80h It doesn't display the contents of edx on the terminal, though I think I told it to with mov eax,4 etc. Anyone able to

X86-64 NASM calling extern c functions

…衆ロ難τιáo~ 提交于 2019-12-31 07:54:26
问题 Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? 回答1: Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to

X86-64 NASM calling extern c functions

混江龙づ霸主 提交于 2019-12-31 07:54:04
问题 Im very new to assembly but know a bit of c. Im playing around with extern function calls like extern _printf str db "Hello", 0 push str call _printf but cant find any tutorials using extern functions except scanf and printf. For example strcmp? How can i call strcmp in my case? 回答1: Here is my answer. It is specific to x86-64 though. Please know that when pushing arguments to a function, you usually place the first 6 in registers rdi , rsi , rdx , rcx , r8 , and r9 . The rest get pushed to

Does pushing a register empty that register?

北城以北 提交于 2019-12-31 05:41:34
问题 I have read many books and instructions on this, but one thing that is never specified is what happens to a register after you push it on the stack. For example if you write in assembly "push ECX", the contents of the ECX register will be pushed on the stack (obviously). What I don't know is, once you did this, does the ECX register keep the value it contained before the push, or did it empty itself after the push? 回答1: CPUs almost always copy , not copy + zero-the-src . Despite instruction

Insert values into array and display, nasm

元气小坏坏 提交于 2019-12-31 05:27:14
问题 First of all, this is a homework assignment. I have a loop to get values of two digits individually, and joining them by doing a multiplication of the first digit by 10 and adding with the second digit to get an integer. I'm doing all this and saving in my AL register, and now I want to insert that integer into an array and then scan that array and display those numbers. How can I insert into vector and read from vector? My array: section .bss array resb 200 My digit convert: sub byte[digit

Segmentation-fault error happening with Assembly code program

允我心安 提交于 2019-12-31 04:12:53
问题 I keep getting a segmentation fault error when running my code. Everything has compiled well, but I can't seem to get it to do what I want. The program is to ask the user to enter 3 integers, then ask the user what they think the average of the numbers would be, take that into account and then come back with whether or not the user guessed correctly segment .data ; ; Output strings ; prompt1 db "Enter a positive integer: ", 0 prompt2 db "Enter a second positive integer: ", 0 prompt3 db "Enter

Learning Assembly, Issue With Code?

本小妞迷上赌 提交于 2019-12-31 04:00:31
问题 jmp start ;============================== ; Draws a horiz and vert line ;============================== startaddr dw 0a000h ;start of video memory colour db 1 ;============================== start: mov ah,00 mov al,19 int 10h ;switch to 320x200 mode ;============================= horiz: mov es, startaddr ;put segment address in es ; <--- Error Line 14 mov di, 32000 ;row 101 (320 * 100) add di, 75 ;column 76 mov al,colour ;cannot do mem-mem copy so use reg mov cx, 160 ;loop counter hplot: mov

Printing “array” from .bss in gdb

主宰稳场 提交于 2019-12-30 23:08:18
问题 my nasm x86 assembly code contains the following: ; The code should mimic the following C-code: ; int a[10]; ; for (int i = 0; i < 10; i++){ ; a[i] = i; ; } SECTION .data arraylen dd 10 SECTION .bss array RESD 10 SECTION .text global main main: mov ecx, 0 mov eax, 0 loop: inc ecx mov dword [array+eax*4], ecx inc eax cmp ecx, arraylen jl loop end: mov ebx, 0 mov eax, 1 int 0x80 Now what i want is to check whether this code works in gdb. However, how do i print array ? print array only returns

Loading second stage of a bootloader

一笑奈何 提交于 2019-12-30 06:49:06
问题 I'm trying to create a small operating system for x86 machines and started writing the code for a fairly minimal bootloader. The bootloader I created is quite simple, it loads a small second bootloader from the sector located directly after the master boot record and jumps to that code. The bootloader code in the master boot record seems to run fine, the problem occurs when it tries to jump to the second stage bootloader. This second stage bootloader is supposed to output a letter indicating