问题
This small piece of code works fine on bochs 2.6, but doesn't seem to work on 'real' computers (I've tried several of them). It seems like lodsb is causing the problem, since it worked fine, when I did hello world by printing the string "manually" character by character.
.code16
.text
.globl _start
_start:
movw $0, %ax
jmp main
### DATA AND BUFFERS ###
welcome:
.asciz "welcome"
main:
movw $welcome, %si
call print_string
hang:
jmp hang
print_string:
lodsb
cmp $0, %al
je done
mov $0x0e, %ah
int $0x10
jmp print_string
done:
ret
. = _start + 510
.byte 0x55
.byte 0xaa
Since I don't have a debugger on my 'real' computer I can't quite figure out what is the problem and restarting computer so many times becomes really frustrating. Can the problem be with segment registers?
Problem solved: Issue was with the direction flag, that unlike bochs was set backwards when bios jumped on my code. For more details and suggestions to avoid further problems see the answers below.
来源:https://stackoverflow.com/questions/36195242/code-works-on-bochs-but-does-not-on-real-computer-x86-real-mode