nasm

Null-terminated string, opening file for reading

做~自己de王妃 提交于 2021-01-27 15:59:08
问题 I'm experimenting with sys_open syscall and I get file descriptor for reading. Here is my program: SYS_exit equ 0x3C SYS_open equ 0x02 O_RDONLY equ 0x00 O_WRONLY equ 0x01 O_RDWR equ 0x02 section .text global _start _start: mov eax, SYS_open mov rdi, file_name mov rsi, O_RDONLY mov rdx, 0x00 syscall mov eax, SYS_exit mov rdi, 0x00 syscall section .data file_name: db '/path/to/test\0' So when I ran strace ./bin I got the output: open("/path/to/test\\0", O_RDONLY) = -1 ENOENT (No such file or

What causes “x.asm:(.text+0xd): undefined reference to `y'”?

匆匆过客 提交于 2021-01-27 15:52:24
问题 For a long time I had not programmed with C and Assembler (about 2 years). Now I have decided to start again but I would like to do something much more complicated. I thought about creating a simple kernel. Now I found this source code on the internet: boot.asm: global loader extern kernel_main MAGIC equ 0xbad FLAGS equ 0x3 CHECKSUM equ -(MAGIC+FLAGS) section .text align 4 dd MAGIC dd FLAGS dd CHECKSUM loader: call kernel_main cli quit: hlt jmp quit kernel.c: void print(char *text) { char

What causes “x.asm:(.text+0xd): undefined reference to `y'”?

限于喜欢 提交于 2021-01-27 14:57:16
问题 For a long time I had not programmed with C and Assembler (about 2 years). Now I have decided to start again but I would like to do something much more complicated. I thought about creating a simple kernel. Now I found this source code on the internet: boot.asm: global loader extern kernel_main MAGIC equ 0xbad FLAGS equ 0x3 CHECKSUM equ -(MAGIC+FLAGS) section .text align 4 dd MAGIC dd FLAGS dd CHECKSUM loader: call kernel_main cli quit: hlt jmp quit kernel.c: void print(char *text) { char

Difference between db and dw when defining strings

谁都会走 提交于 2021-01-27 12:26:30
问题 In NASM assembly, there are db and dw pseudo instructions to declare data. NASM Manual provides a couple of examples but doesn't say directly what's the difference between them. I've tried the following "hello world" code with both of them, and it turned out that no difference is observable. I suspect the distinct has something to do with internal data format, but I don't know how to inspect that. section .data msg db "hello world",10,13,0 msg2 dw "hello world",10,13,0 section .text global

Difference between MOV r/m8,r8 and MOV r8,r/m8

荒凉一梦 提交于 2021-01-27 04:39:44
问题 By looking at intel volume of instructions, I found this: 1) 88 /r MOV r/m8,r8 2) 8A /r MOV r8,r/m8 When I write a line like this in NASM, and assemble it with the listing option: mov al, bl I get this in the listing: 88D8 mov al, bl So obviously NASM chosed the first instruction of the two above, but isn't the second instruction an option two? if so, on what basis did NASM chosed the first? 回答1: These two encodings exist because a modr/m byte can only encode one memory operand. So to allow

Bootloader is Not loading the kernel

江枫思渺然 提交于 2021-01-24 10:56:47
问题 I am developing my Operating System. I got error on booting my OS. The error was: KERNEL.BIN not found! Here are the Codes: Boot.asm ; The Aqua_Seven_OS Operating System bootloader ; ================================================================== BITS 16 jmp short bootloader_start ; Jump past disk description section nop ; Pad out before disk description ; ------------------------------------------------------------------ ; Disk description table, to make it a valid floppy ; Note: some of

Having no luck with data NASM

北战南征 提交于 2021-01-20 12:19:50
问题 section .data map db 1 section .text start: cmp byte [map], 1 je exit jmp start exit: ret I'm having no luck reading data. What I mean is that I assemble to the binary dos COM format and when I start it it just freezes. Can someone tell me what i'm doing wrong? 回答1: DOS com files are expected to be loaded at address 0x100. You should include line org 0x100 at the start of your code. 来源: https://stackoverflow.com/questions/26424041/having-no-luck-with-data-nasm

Iterating through an array in NASM assembly code

女生的网名这么多〃 提交于 2021-01-20 07:30:14
问题 So I'm currently taking an assembly language class and we are trying to create and sort an array from input. I can get the sorting logic just fine, but I'm having a great deal of trouble trying to iterate through the array. For further clarification of what the following code does, we are supposed to read in integers from the command line. The number 0 delimits the end of user input, and then the sorting method is called. That works fine, it's the array iteration that is not working. Here is

Should using MOV instruction to set SS to 0x0000 cause fault #GP(0) in 64-bit mode?

天涯浪子 提交于 2021-01-19 21:18:53
问题 This question is inspired by a Reddit question in r/osdev except that this question focuses on the SS register. One may say RTFM (ISA entry for MOV), but when this question comes up it can get varying answers even among OS developers. Question : Should using the MOV instruction to set SS to 0x0000 cause a general protection fault #GP(0) in 64-bit mode? For example: If I am in 64-bit mode with a Current Privilege level (CPL) of 0, should I expect to see a #GP(0) with this code snippet: NULL

Should using MOV instruction to set SS to 0x0000 cause fault #GP(0) in 64-bit mode?

半城伤御伤魂 提交于 2021-01-19 21:18:33
问题 This question is inspired by a Reddit question in r/osdev except that this question focuses on the SS register. One may say RTFM (ISA entry for MOV), but when this question comes up it can get varying answers even among OS developers. Question : Should using the MOV instruction to set SS to 0x0000 cause a general protection fault #GP(0) in 64-bit mode? For example: If I am in 64-bit mode with a Current Privilege level (CPL) of 0, should I expect to see a #GP(0) with this code snippet: NULL