nasm

Print a number in NASM - building an x86 Bootsector

送分小仙女□ 提交于 2019-12-29 09:27:32
问题 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 int 21h ret I know I can do it using extern _printf but I want try it with interrupts. I thought 21h is a windows interrupt. So, what interrupt code should I use? 回答1: Here's an example from a course that I teach. This is a raw bootsector that

Cannot find crtn.o, linking 32 bit code on 64 bit system

◇◆丶佛笑我妖孽 提交于 2019-12-29 06:19:52
问题 I'm attempting to assemble some 32-bit code using NASM and GCC on a 64-bit system. I use the following two commands nasm -f elf32 -g -F stabs coc.asm gcc -m32 -o coc coc.o NASM appears to do fine, but LD complains: /usr/bin/ld: cannot find crt1.o: No such file or directory /usr/bin/ld: cannot find crti.o: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/libgcc.a when searching for -lgcc /usr/bin/ld: cannot find -lgcc /usr/bin/ld: skipping

How do i read single character input from keyboard using nasm (assembly) under ubuntu?

有些话、适合烂在心里 提交于 2019-12-28 18:06:33
问题 I'm using nasm under ubuntu. By the way i need to get single input character from user's keyboard (like when a program ask you for y/n ?) so as key pressed and without pressing enter i need to read the entered character. I googled it a lot but all what i found was somehow related to this line ( int 21h ) which result in "Segmentation Fault". Please help me to figure it out how to get single character or how to over come this segmentation fault. 回答1: It can be done from assembly, but it isn't

How do i read single character input from keyboard using nasm (assembly) under ubuntu?

↘锁芯ラ 提交于 2019-12-28 18:06:12
问题 I'm using nasm under ubuntu. By the way i need to get single input character from user's keyboard (like when a program ask you for y/n ?) so as key pressed and without pressing enter i need to read the entered character. I googled it a lot but all what i found was somehow related to this line ( int 21h ) which result in "Segmentation Fault". Please help me to figure it out how to get single character or how to over come this segmentation fault. 回答1: It can be done from assembly, but it isn't

NASM module to convert hex into string and print it out. Assembles but not working as expected

蹲街弑〆低调 提交于 2019-12-25 18:26:49
问题 I am trying to write a simple assembly code to spit out hex values to the screen. There are two files print_screen.asm which is working with other modules. I think the problem is in my logic when trying to convert hex to string. My code is: [org 0x7c00] xor dx,dx xor ax,ax xor bx,bx mov dx, 0x1fb6 call print_hex jmp endi; print_hex: pusha mov ax,0x0001 and ax,dx add ah,48 mov byte [HEX_OUT+5],ah mov ax,0x0010 and ax,dx add ah,48 mov byte [HEX_OUT + 4],ah mov ax,0x0100 and ax,dx add ah,48 mov

Segmentation Fault on simple ASM code

拈花ヽ惹草 提交于 2019-12-25 12:22:11
问题 For my Question when I tried to create a example of NASM under ubuntu 64-bit version and execute it after assembled and linked into ELF. It return error messages as below when I execute NASM -f elf64 -o firstasm.o firstasm.asm ld -o firstasm firstasm.o firstasm Segmentation fault (core dumped) My NASM code would be below where I tried to perform simple write() and exit() function section .data ;Data segment msg db "This line is test", 0x0a section .text ;text segment global _start ;Default

Two digit string number Assembly

眉间皱痕 提交于 2019-12-25 09:38:31
问题 So I have to strings s1 and s2 and I have two obtain the string d that contains the maximum numbers for each of the positions of s1 and s2. For example: S1: 1, 3, 6, 2, 3, 10 S2: 6, 3, 11, 1, 2, 5 D: 6, 3, 11, 2, 3, 10 So this is the code bits 32 global start extern exit,printf import exit msvcrt.dll import printf msvcrt.dll segment data use32 class=data format db "%s",0 s1 db "1","3","6","2","3","10" l equ $-s1 s2 db "6","3" ,"11","1","2", "5" d times l db 0 segment code use32 class=code

IDIV in assembly isn't giving me the wanted result (NASM)

試著忘記壹切 提交于 2019-12-25 07:26:42
问题 I'm trying to do a simple division: mov ebx, 10 mov eax, 1111111111 ;(10 times) mov edx, 0 idiv bx Supposedly I want to get the following results: edx = 1 eax = 111111111 (9 times) But the results I'm getting are: edx = 7 eax = 1111098720 Does anyone know what the problem might be? Thanks 回答1: mov ebx, 10 mov eax, 1111111111 ;(10 times) mov edx, 0 idiv bx What immediately strikes me is that you setup all registers for 32 -bit operation but then perform a 16 -bit division. Changing it to the

How to print strings in assembly language

▼魔方 西西 提交于 2019-12-25 04:05:18
问题 I am trying to print a string in Q Emulator using NASM. My code is as below: mov bx,HELLO mov ah, 0x0e int 0x10 HELLO: db 'Hello', 0 jmp $ times 510-($-$$) db 0 dw 0xaa55 However when I compile this code, the output that I get is UU Can anyone please tel me why this is so? And how to get the required string as output? Thanks in advance. 回答1: ALRIGHT SO here is a thingamabob to your question In order to load the string, you must move it into si (don't really want to go to deep but just do it).

Makefile does not “see” %.o %.asm rule

北慕城南 提交于 2019-12-25 03:48:08
问题 I'm writing a project and wanted to make one, good makefile. At some point I noticed that it doesn't work for multiple .asm files, I did some research and modified my file, so it looks like this: PROJDIRS := kernel lib ASMFILES := $(shell find $(PROJDIRS) -type f -name "*.asm") SRCFILES := $(shell find $(PROJDIRS) -type f -name "*.c") HDRFILES := $(shell find $(PROJDIRS) -type f -name "*.h") ASMOBJCT := $(patsubst %.asm,%.o,$(ASMFILES)) OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) TSTFILES :=