2014-12-29 24 views
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

如果有人能帮助我,我将不胜感激。另外,如果你注意到我的代码中有其他不同寻常的东西,请随时告诉我。我正在开发这个作为第一阶段的引导程序,进入二级内核。

预先感谢您的建议和考虑。

+1

mov指令要求两个操作数的位长相同。因此cl不能将ax(16位寄存器)移入cl,因为cl有8位。有效的备选方案:mov cl,al或mov cl,ah。 –

+1

愚蠢的错误,我们都做到了,所以这是一个很好的问题,但我想让你知道我刚刚投了你的问题+1,不是因为这是我以前做过47次的愚蠢错误,而是因为你已经很好地评论了你的代码;每条指令,以及各个部分的标题。这是受到关注的那种代码;并得到回答。 –

+0

@ User.1非常感谢您的客气话,我很高兴我的问题令其他用户(如您自己)感到满意。 –

回答

4

作为对原始问题的评论陈述,问题在于您试图将16位寄存器的内容移动到8位寄存器中。你不能这样做,因为寄存器大小不同。

如果您想将数据从AX寄存器移动到CL寄存器中,您必须决定是要低位(AL寄存器)还是高位(AH寄存器)。也就是说,你可以写:

mov cl,al ; moves the low 8 bits of AX into CL 

或者

mov cl,ah ; moves the high 8 bits of AX into CL 

但是你不能把AX的全部16位到CL的8位。

现在,考虑你的代码。您有:

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 

这是行不通的好,因为你打电话lbachs得到的AX,BX和CX寄存器的一些信息,但是你马上踩在脚下AH和AL(两半斧头)。你需要改变你的操作顺序,这样你才不会覆盖东西。我想你想的是一样的东西:

call lbachs 

mov ch, cl  ; Cylinder (returned in CX by lbachs) 
mov cl, al  ; sector number (returned in AX by lbachs) 
mov dh, bl  ; head (returned in BX by lbachs) 
mov ah, 02  ; Read disk sectors function 
mov al, 0x01 ; one sector 
mov dl, 0x00 ; Drive 0 

注意,这里我用lbachs返回的值,然后覆盖在被送回这些值的寄存器。