1
我试图将存储在我的AX寄存器中的值移至CL寄存器。我也试图用寄存器对(从移动到BX:DH和CX:CH)执行此操作。将AX移入CL - 操作码和操作数无效组合
这是我的代码。
;;;
;;; Stage 1 - Boot Loader
;;;
BITS 16 ; Start in 16 bit real mode
ORG 0x7C00 ; Loaded by BIOS at 0x7C00
start: jmp stage1 ; Jump to the stage 1 section
;;;
;;; Parameter Block
;;;
SECTORS_TRACK dw 18 ; Sectors per track
HEADS_CYLINDER dw 2 ; Heads per cylinder
;;;
;;; Strings Block
;;;
stage1_message db 'Stage 1 - 16 bit real mode', 13, 10, 0
;;;
;;; Print String Function
;;; Input:
;;; - si = Null terminated string
;;; Output:
;;; - None
;;;
print:
lodsb ; Load next byte from string in SI to AL
or al, al ; Does AL equal 0?
jz print_done ; Yes, null terminator found, return
mov ah, 0eh ; No, print the character
int 10h
jmp print ; Repeat until null terminator found
print_done:
ret ; We are done, return
;;;
;;; LBA to CHS Function
;;; - Sector 1 = LBA 0
;;; Input:
;;; - ax = LBA value
;;; Output:
;;; - ax = Sector
;;; - bx = Head
;;; - cx = Cylinder
;;; Credit:
;;; - http://www.osdever.net/tutorials/view/lba-to-chs
;;;
lbachs:
push dx
xor dx, dx
mov bx, [SECTORS_TRACK]
div bx
inc dx
push dx
xor dx, dx
mov bx, [HEADS_CYLINDER]
div bx
mov cx, ax
mov bx, dx
pop ax
pop dx
ret
;;;
;;; Load Stage 2 Function
;;;
stage2:
mov ax, 0x01 ; LBA 1 = Sector 2
call lbachs ; Convert LBA to CHS
mov ah, 0x02 ; Read disk sectors function
mov al, 0x01 ; Read one sector only (512 bytes)
mov dl, 0x00 ; Drive 0 (Floppy Disk 1)
mov cl, ax ; Sector - Stored in AX - ERROR
mov dh, bx ; Head - Stored in BX - ERROR
mov ch, cx ; Cylinder - Stored in CX - ERROR
mov bx, 0x2000 ; Put loaded data into segment 0x2000:0x0000
mov es, bx ; Load segment into ES (Segment parameter)
mov bx, 0x0000 ; Load segment offset into BX (Offset parameter)
int 0x13 ; Call BIOS read disk sectors function
jc stage2 ; Error occurred, try loading again
jmp 0x2000:0x0000 ; Loading complete, jump to stage 2
;;;
;;; Stage 1 Section
;;;
stage1:
mov si, stage1_message ; Load the stage 1 message
call print ; Call the print function
jmp stage2 ; Attempt to load stage 2
;;;
;;; Footer Information
;;;
times 510-($-$$) db 0 ; Fill remainder of bootloader with 0's
dw 0xAA55 ; Standard PC boot signature at the end
三线导致问题的上方附近stage1:
底部,并标有字样ERROR
如果有人能帮助我,我将不胜感激。另外,如果你注意到我的代码中有其他不同寻常的东西,请随时告诉我。我正在开发这个作为第一阶段的引导程序,进入二级内核。
预先感谢您的建议和考虑。
mov指令要求两个操作数的位长相同。因此cl不能将ax(16位寄存器)移入cl,因为cl有8位。有效的备选方案:mov cl,al或mov cl,ah。 –
愚蠢的错误,我们都做到了,所以这是一个很好的问题,但我想让你知道我刚刚投了你的问题+1,不是因为这是我以前做过47次的愚蠢错误,而是因为你已经很好地评论了你的代码;每条指令,以及各个部分的标题。这是受到关注的那种代码;并得到回答。 –
@ User.1非常感谢您的客气话,我很高兴我的问题令其他用户(如您自己)感到满意。 –