2011-11-21 29 views
1

我是新来的编程在asm。我试图创建一个在引导扇区上打印消息的软盘,跳到扇区35并打印日期,然后跳回到引导扇区并打印提示。我遇到了麻烦(我认为)在扇区之间跳跃......当引导扇区上的所有东西都打印好了,并且我没有更改实际的打印代码。我目前得到的是消息的第一行,然后日期和提示不会打印。代码如下;我使用NASM:如何在装配中的软盘之间跳转? - 使用NASM远程呼叫和retf?

对于引导扇区:

org 0x7c00 ;load to appropariate MBR location 

start: 
    call cls ;call routine to clear screen 
    call dspmsg ;call routine to display message 

    mov ah,02h ;read disk sectors into memory 
    mov al,1 ;number of sectors to read/write (must be nonzero) 
    mov ch,1 ;cylinder number (0...79) 
    mov cl,18 ;sector number (1...18) 
    mov dh,0 ;head number (0...1) 
    mov dl,0 ;drive number (0...3, 0 for floppy) 
    mov bx, 0x1000 
    mov es,bx 
    mov bx,0x0000 
    int 13h 

    call word 0x1000:0x0000 

    push cs 
    pop ds 

    call dspmsg2 

    jmp $ 

%macro dsp 3 
mov ah,13h ;function 13h (Display String) 
mov al,1 ;Write mode is one 
mov bh,0 ;Use video page of zero 
mov bl,0AH ;Attribute 
mov cx,%1 ;Character string length 
mov dh,%2 ;position on row 
mov dl,0 ;and column 28 
push ds ;put ds register on stack 
pop es ;pop it into es register 
lea bp,%3 ;load the offset address of string into BP 
int 10H 
%endmacro 

cls:    
    mov ah,06h ;function 06h (Scroll Screen) 
    mov al,0 ;scroll all lines 
    mov bh,0AH ;Attribute (light green on black) 
    mov ch,0 ;Upper left row is zero 
    mov cl,0 ;Upper left column is zero 
    mov dh,24 ;Lower left row is 24 
    mov dl,79 ;Lower left column is 79 
    int 10H ;BIOS Interrupt 10h (video services) 
    ret 

msg: db 'OS321, made by CHRISTINE MCGINN (c) 2011' 

dspmsg: 
    dsp 40,0,[msg] 
    ret 

msg2: db '$' 

dspmsg2: 
;Display a message 
dsp 1,2,[msg2] 
ret 

times 510-($-$$) db 0 ;Pad remainder of boot sector with 0s 
dw 0xAA55 ;done setting the MBR 

然后在扇形体35:

org 0x0000 

push cs 
pop ds 

    call date 
    call cvtmo 
    call cvtday 
    call cvtcent 
    call cvtyear 

    call time 
    call cvthrs 
    call cvtmin 
    call cvtsec 
    call dsptimedate 

    retf 

%macro dsp 3 
mov ah,13h ;function 13h (Display String) 
mov al,1 ;Write mode is one 
mov bh,0 ;Use video page of zero 
mov bl,0AH ;Attribute 
mov cx,%1 ;Character string length 
mov dh,%2 ;position on row 
mov dl,0 ;and column 28 
push ds ;put ds register on stack 
pop es ;pop it into es register 
lea bp,%3 ;load the offset address of string into BP 
int 10H 
%endmacro 

%macro cvt 3 
mov bh,%1 ;copy contents of %1 to bh 
shr bh,1 
shr bh,1 
shr bh,1 
shr bh,1 
add bh,30h ;add 30h to convert to ascii 
mov [tmdtfld + %2],bh 
mov bh,%1 
and bh,0fh 
add bh,30h 
mov [tmdtfld + %3],bh 
%endmacro 

date: 
;Get date from the system 
mov ah,04h ;function 04h (get RTC date) 
int 1Ah  ;BIOS Interrupt 1Ah (Read Real Time Clock) 
ret 

;CH - Century 
;CL - Year 
;DH - Month 
;DL - Day 

cvtmo: 
;Converts the system date from BCD to ASCII 
cvt dh,9,10 
ret 

cvtday: 
cvt dl,12,13 
ret 

cvtcent: 
cvt ch,15,16 
ret 

cvtyear: 
cvt cl,17,18 
ret 

time: 
;Get time from the system 
mov ah,02h 
int 1Ah 
ret 

;CH - Hours 
;CL - Minutes 
;DH - Seconds 

cvthrs: 
;Converts the system time from BCD to ASCII 
cvt ch,0,1 
ret 

cvtmin: 
cvt cl,3,4 
ret 

cvtsec: 
cvt dh,6,7 
ret 

tmdtfld: db '00:00:00 00/00/0000' 

dsptimedate: 
;Display the system time 
dsp 19,1,[tmdtfld] 
ret 

times 512-($-$$) db 0 ;Pad remainder of sector with 0s 

谢谢您可以提供任何帮助!

+0

我卡在同一个地方。由于错误的扇区或磁头,我认为软盘读取失败。我使用虚拟机来测试它,但我不知道虚拟软盘驱动器有多少个磁头,也没有它的其他属性..:D – Rolice

回答

1

您已经以令人困惑的方式提出问题。你似乎有两个问题:

1)从具有各部门的做一些程序软盘

2)读任意部门(如打印字符串)

我会安排我的计划作为一个软盘驱动器(可能是 使用BIOS来完成大部分肮脏的工作,但这是一个实现细节),并且作为一组独立的位置无关代码块作为子程序的各种任务 。

你的引导扇区代码应包含软盘驱动器和高层次的逻辑 读取扇区(N),请致电您阅读板块流入, 然后做下一个扇区缓冲区中的子程序。 (你没有太多的空间,所以我不知道 ,如果你能把所有这些都放到引导扇区中,欢迎使用汇编语言 ,其中计数字节很重要)。

然后你必须以某种方式组织软盘的构建。 通常在一个创建可引导软盘的世界中,您可以构建更复杂的程序来填充它们。运动留给读者。