我正在制作引导加载程序,作为学习汇编的一种方式。我已经研究过使用部分来组织和优化我的代码,但是当我调用 printf 函数时,一件事不起作用。当我在 .data 部分中有 HELLO_WORLD 字符串时,它根本不想加载该字符串
; Set Code to run at 0x7c00
org 0x7c00
; Put into real mode
bits 16
; Variables without values
section .bss
; Our constant values
section .data
HELLO_WORLD: db 'Hello World!', 0
; Where our code runs
section .text
_start:
mov si, HELLO_WORLD ; Moves address for string into si register
call printf ; Calls printf function
jmp $ ; Jump forever
printf:
lodsb ; Load the next character
cmp al, 0 …Run Code Online (Sandbox Code Playgroud) 我很好奇如果我把db 0x41这个.text部分放在它通常所属的地方,而不是放在.data它通常所属的地方,会发生什么。它会出现段错误,但到底为什么呢?
下面的代码是在 Mint 19.1 中使用 和 进行编译、链接和执行nasm的ld。
无段错误:
global _start
section .data
db 0x41
section .text
_start:
mov rax, 60 ; Exit(0) syscall
xor rdi, rdi
syscall
Run Code Online (Sandbox Code Playgroud)
段错误:
global _start
section .text
_start:
db 0x41
mov rax, 60 ; Exit(0) syscall
xor rdi, rdi
syscall
Run Code Online (Sandbox Code Playgroud)
我使用以下命令来组装、链接和运行它:
global _start
section .data
db 0x41
section .text
_start:
mov rax, 60 ; Exit(0) syscall
xor rdi, rdi
syscall
Run Code Online (Sandbox Code Playgroud) 我用的是emu8086。我有一个问题,要求我在从六段输入转换后显示我们在七段显示器上看到的内容。我应该以十六进制输入我的数据,如果它与七段表的十六进制输入匹配,则显示十进制数,例如。3FH = 0, 06H = 1。我使用数组来实现这个程序。下面是工作源程序:
\nORG 100H \n\nMOV AL,[1840H] \xef\xbc\x9binput in this memory location\nMOV CL,0AH ; initialize length counter\n \nAGAIN: CMP AL,MSG+BX ; compare to check if the data matches\n JE RESULT ; jump to RESULT if data matched\n INC BX ; increase decimal output by 1 if data not matched\nLOOP AGAIN\n\nMOV [1841H],0FFH ; display FF if no data matched the array\n\nHLT\n\nMSG DB 3FH, 06H, 5BH, 4FH,66H, 6DH,7DH,07H,7FH,6FH ; my array with hexa inputs\n\nRESULT: MOV [1841H],BL ; display …Run Code Online (Sandbox Code Playgroud)