例如,如果我有一条像 00010101 这样的指令,并且我将它放在 ram 中供程序访问,我如何能够在不使用 OS 函数的情况下以汇编语言执行该指令?我正在将 Fasm 用于英特尔。谢谢。
编辑:我知道这是非常糟糕的代码,我什至还没有组装它,我知道很多都是错误的,但请记住这是出于学习目的。这是加载带有二进制指令的文件并将其存储在 ram 中的代码部分。我再一次知道这很糟糕。
loadkernel:
mov dx, 1F7h
in dx, bl
bt bl, 6 ;this reads the sixth bit of bl and stores it in the carry flag(cf)
cmp cf, 1 ;if bit 6 is one, then the hard drive is signaling that it is ready for the next operation
jz loadkernel
clc ;clear carry flag
beginload:
mov eax, 300h
mov ecx, eax ;copy the starting point of the kernel in memory to ecx
mov ebx, 0 ;clear
mov edx, 0 ;clear
mov bl, 1F4h
out ebx, bl ;give the hard drive the low address of the location of the kernel
mov bl, 1F5h
out 0h, bl ;give the hard drive the high address of the location of the kernel
mov bl, 1F0h
in edx, bl ;read the hard drive
mov [eax], edx ;add kernel data to memory
add eax, 1
inc ebx ;move the hard drive reading head thing forward
mov ip, [eax] ;mov the instruction pointer to memory, so that the computer excecutes the kernel
cmp edx, 0AA55h
jz beginload ;if 0AA55h is not at the end, then read the next data of the kernel.