I was writing a bootsector based on a FAT12 filesystem. After a while I came up with a problem.
.FindBootSectorTwo:
push SI
push DI
push CX
mov CX, 11
mov SI, BootloaderSTG2
rep cmpsb
pop CX
pop DI
pop SI
je LOAD_BOOTLOADER_STG2
nop
add DI, 32
loop .FindBootSectorTwo
jmp ERROR_NOT_FOUND
This label searches for a file called BLS2.SYS and if it finds it, it jumps to LOAD_BOOTLOADER_STG2 label. The beginning of LOAD_BOOTLOADER_STG2 label:
LOAD_BOOTLOADER_STG2:
push SI
push CX
push DI
;sub DI, 32
mov SI, DI
mov CX, 11
call Printname
pop DI
pop CX
pop SI
pop DS
If I try to subtract 32 from DI, it gives me the right file name -- BLS2.SYS, but if I don't , I get only a bunch of spaces. What could be the problem here? Is this is a bug, that the program finds the wrong file, or I just don't understand something here? I'm launching this code on Bochs, on a x86 machine. P.S. here's the LOAD_ROOT label together with .FindBootSectorTwo.
LOAD_ROOT: ; in this label I search for an entry to Root directory, where my file is. When I find the root directory, I load it at: 0x0800:0x0000
mov [BS_DriveNumber], DL
mov AX, 0x0000
mov SS, AX
mov SP, 0x7C00
mov DS, AX
mov ES, AX
xor DX, DX
movzx AX, [BPB_NumberOfFATs]
mov BX, [BPB_SectorsPerFAT]
mul BX ; BX = NumFATS * SecPerFAT
mov BX, AX
add BX, [BPB_ReservedSectors] ; BX now contains LBA value aka NumFATS * SecPerFAT + ResvSecs
push DI
push ES
mov AX, [BPB_RootEntries]
shl AX, 5
xor DX, DX
div WORD[BPB_BytesPerSector] ; AL = (RootEntries * 32) / BytesPerSec
mov AH, 0x0002
push AX
mov AX, 0x0800
mov ES, AX ; ES = 0x0800
pop AX
mov DI, 0x0000
call ReadSectors
mov CX, [BPB_RootEntries]
push DS
push AX
mov AX, 0x0800
mov ES, AX
mov DS, AX
pop AX
mov DI, 0x0000
.FindBootSectorTwo: ; here I search for a file called BLS2.SYS (at 0x0800:0x0000), when I find it, the program jumps to LOAD_BOOTLOADER_STG2
push SI
push DI
push CX
mov CX, 11
mov SI, BootloaderSTG2
rep cmpsb
pop CX
pop DI
pop SI
je LOAD_BOOTLOADER_STG2
nop
add DI, 32
loop .FindBootSectorTwo
jmp ERROR_NOT_FOUND
If you need any additional peaces of code -- tell me. I'll give you whatever you need.
The code is subtracting 32 from DI so points to the beginning of the file name string. Then you can print it accordingly.
Related
I need to reverse a given string in assembly 8086. I wrote a code that should work but I get the output
'MAGSM$HIMI
instead of
MAGSHIMIM
I can't figure out what is the problem with the code. I suspect the "$" is causing the problem but I have no idea.
My code:
org 100h
jmp main
chrs db 'M','I','M','I','H','S','G','A','M', '$'
main:
mov bp, sp
mov ax,offset chrs
call print_ax_str
mov ax, offset chrs
push ax
push 9
call reverse
PRINTN ;new line
mov ax,offset chrs
call print_ax_str
jmp stop
reverse proc
; First save the old BP
push bp
; Now establish new BP
mov bp, sp
;make space for 2 local variables
sub sp, 4
mov dx, [bp+6]
mov bx, [bp+4] ;bx = 9
dec bx ;bx = 8
add dx, bx ; dx = dx + 8
mov di, dx
mov SI, [bp+6]
mov cx, 4
L1:
mov dx, [si]
xchg ax, [di]
mov [si], ax
mov [di], dx
inc si ;si--
dec di ;di++
loop L1
mov sp, bp
; Restore OLD BP
pop bp
retn 4
reverse endp
stop:
mov ah, 0
int 16h
ret
include magshimim.inc
chrs db 'M','I','M','I','H','S','G','A','M', '$'
...
L1:
mov dx, [si]
xchg ax, [di]
mov [si], ax
mov [di], dx
inc si ;si--
dec di ;di++
loop L1
The biggest problem here is that your chrs string contains bytes but your reversing procedure works with words (2 bytes).
Looking at this loop I suspect that you've mixed 2 solutions to the reversing problem. The xchg ax, [di] instruction tells this.
Solution 1 using MOV
L1:
mov dl, [si]
mov al, [di]
mov [si], al
mov [di], dl
inc si ;si++
dec di ;di--
loop L1
Solution 2 using XCHG
L1:
mov dl, [si]
xchg dl, [di]
mov [si], dl
inc si ;si++
dec di ;di--
loop L1
Please notice that the comments in your code were wrong. Incrementing SI corresponds to "si++". Similarly decrementing DI corresponds to "di--".
Since you pass the length of the string to the procedure and have the pointers based on it, you should also base your loop counter on it and not use a fixed count of 4 via mov cx, 4.
mov cx, [bp+4] ;SLen
shr cx, 1 ;SLen/2
L1:
With some additional clean-up:
reverse proc
push bp
mov bp, sp
mov cx, [bp+4] ;SLen
mov si, [bp+6]
mov di, si
add di, cx
dec di
shr cx, 1 ;SLen/2
L1:
mov dl, [si]
mov al, [di]
mov [si], al
mov [di], dl
inc si ;si++
dec di ;di--
loop L1
pop bp
retn 4
reverse endp
So I'm writing a uni assignment - a program that subtracts two entered decimals (max 10 characters ea). The first iteration works as intended. However, when I restart the program, for some reason the second operand is remembered.
The prompt to enter it does come up, but is then skipped as if I've entered something already - the same thing I entered the first iteration, in fact.
The question is: why does it happen and how do I fix it? The first prompt works correctly.
The prompt is under INPUT_2:
.model small
.386
stack 100h
dataseg
inputMsg1 db 0Ah, 0Dh, 'Enter first operand', 0Ah, 0Dh, '$'
inputMsg2 db 0Ah, 0Dh, 'Enter second operand', 0Ah, 0Dh, '$'
inputMax1 db 11
inputLen1 db ?
input1 db 12 dup(?)
input1Packd db 5 dup(0)
inputMax2 db 11
inputLen2 db ?
input2 db 12 dup(?)
input2Packd db 5 dup(0)
packMode db 0 ;Режим упаковки: 1 - первая цифра, 2 - вторая
resMsg db 0Ah, 0Dh, 'Result: $'
res db 9 dup(' '),'$'
retryMsg db 0Ah, 0Dh
db 'Press Any Key to continue, ESC to quit'
db '$'
errorMsg db 0Ah, 0Dh, 'Something went wrong. Try again$'
codeseg
START:
startupcode
jmp INPUT_1
INPUT_1_ERROR:
lea DX, errorMsg
mov AH, 09h
int 21h
INPUT_1:
lea DX, inputMsg1
mov AH, 09h
int 21h
lea DX, inputMax1
mov AH, 0Ah
int 21h
cmp inputLen1, 0
jz INPUT_1_ERROR
INPUT_1_PROCESS:
lea BX, input1
lea DX, input1Packd
xor CX, CX
mov CL, inputLen1
mov SI, CX
dec SI
mov DI, 4
INPUT_1_LOOP:
mov AL, [BX][SI]
cmp AL, '0'
jb INPUT_1_ERROR
cmp AL, '9'
ja INPUT_1_ERROR
and AL, 0Fh
mov AH, packMode
cmp AH, 0
jnz INPUT_1_PACK_SECOND
INPUT_1_PACK_FIRST:
inc AH
push BX
mov BX, DX
mov [BX][DI], AL
pop BX
jmp INPUT_1_PACK_FINISHED
INPUT_1_PACK_SECOND:
dec AH
shl AL, 4
push BX
mov BX, DX
or [BX][DI], AL
pop BX
dec DI
INPUT_1_PACK_FINISHED:
mov packMode, AH
dec SI
loop INPUT_1_LOOP
mov packMode, 0
jmp INPUT_2
INPUT_2_ERROR:
lea DX, errorMsg
mov AH, 09h
int 21h
INPUT_2:
lea DX, inputMsg2
mov AH, 09h
int 21h
lea DX, inputMax2
mov AH, 0Ah
int 21h
cmp inputLen2, 0
jz INPUT_2_ERROR
INPUT_2_PROCESS:
lea BX, input2
lea DX, input2Packd
xor CX, CX
mov CL, inputLen2
mov SI, CX
dec SI
mov DI, 4
INPUT_2_LOOP:
mov AL, [BX][SI]
cmp AL, '0'
jb INPUT_2_ERROR
cmp AL, '9'
ja INPUT_2_ERROR
and AL, 0Fh
mov AH, packMode
cmp AH, 0
jnz INPUT_2_PACK_SECOND
INPUT_2_PACK_FIRST:
inc AH
push BX
mov BX, DX
mov [BX][DI], AL
pop BX
jmp INPUT_2_PACK_FINISHED
INPUT_2_PACK_SECOND:
dec AH
shl AL, 4
push BX
mov BX, DX
or [BX][DI], AL
pop BX
dec DI
INPUT_2_PACK_FINISHED:
mov packMode, AH
dec SI
loop INPUT_2_LOOP
MATH_SETUP:
mov SI, 4
mov CX, 4
mov DI, 7
MATH:
lea BX, input1Packd
mov AL, [BX][SI]
lea BX, input2Packd
mov AH, [BX][SI]
sbb AL, AH
pushf
das
dec SI
mov AH, AL
lea BX, res
and AL, 0Fh
or AL, 30h
mov [BX][DI], AL
dec DI
shr AH, 4
or AH, 30h
mov [BX][DI], AH
dec DI
popf
loop MATH
lea BX, res
mov CX, 7
mov SI, 0
SHORTEN:
mov AL, [BX][SI]
cmp AL, '0'
jnz WRAPUP
inc SI
loop SHORTEN
WRAPUP:
push CX
lea DX, resMsg
mov AH, 09h
int 21h
lea DX, res
pop CX
cmp CX, 0
jz SKIP_SHORTEN
PRINT_SHORTEN:
add DX, 7
sub DX, CX
jmp FINISH_SHORTEN
SKIP_SHORTEN:
add DX, 6
FINISH_SHORTEN:
mov AH, 09h
int 21h
lea DX, retryMsg
mov AH, 09h
int 21h
mov AH, 01h
int 21h
cmp AL, 1Bh
jz QUIT
lea BX, input1Packd
mov DX, 1
BCD_CLEANUP:
mov DI, 0
mov CX, 5
BCD_CLEANUP_LOOP:
mov [BX][DI], 0
inc DI
loop BCD_CLEANUP_LOOP
lea BX, input2Packd
cmp DX, 1
mov DX, 0
jz BCD_CLEANUP
jmp START
QUIT:
exitcode 0
end START
Any better code suggestions welcome as well, but not needed if you don't have an answer for the question.
The DOS buffered input function 0Ah allows you to have a preset text in the storage space of the input buffer that you provide. For a complete explanation of this DOS function see how buffered input works.
The first time that your program runs the inputLen1 and inputLen2 fields are empty because of how you defined them in the source using db ? which translates to zero.
But when you re-run the code this is no longer the case! The lengths still show what you got in the previous run. You need to zero both these fields before invoking function 0Ah again on the same input buffers.
mov DX, 0
jz BCD_CLEANUP
mov inputLen1, DL ;DL=0
mov inputLen2, DL ;DL=0
jmp START
The MATH loop has a couple of problems regarding the CF.
The sbb al, ah instruction depends on the value in the carry flag, but you neglect to make sure it is off on the first iteration of this loop. Just add clc:
clc
MATH:
lea BX, input1Packd
mov AL, [BX][SI]
lea BX, input2Packd
mov AH, [BX][SI]
sbb AL, AH
The das instruction consumes the carry flag that you get from the sbb instruction, but it's the carry flag that you get from the das instruction that you need to preserve/restore to have it propagate through the loop.
sbb AL, AH
das
pushf
...a program that subtracts two entered decimals (max 10 characters ea)...
If ever you enter 9 or 10 characters, those most significant digits will not be taken into account because MATH_SETUP really limits you to 8 characters (which in turn is a good thing since the res buffer only has room to show 8 characters)!
MATH_SETUP:
mov SI, 4 <-- Could permit 10 packed BCD digits
mov CX, 4 <-- Max 8 characters
mov DI, 7 <-- Max 8 characters
Below i have a code that draw 3 circles in 3 different colors.. that is fine..
but how do i addmit a text string ? Thx.
I did some tests on virtualbox (windows), but no luck..
Any ideas to get it worked ?.
BITS 16
ORG 100h
push 0a000h ;Video memory graphics segment
pop es
mov ax, 0013h ;320x200#8bpp
int 10h
push 0Eh ;Blue
push 10 ;cX
push 10 ;cY
push 10 ;Radius
call drawFilledCircle
push 02h ;Blue
push 40 ;cX
push 40 ;cY
push 30 ;Radius
call drawFilledCircle
push 06h ;Blue
push 140 ;cX
push 100 ;cY
push 70 ;Radius
call drawFilledCircle
;Wait for a key
xor ah, ah
int 16h
loc db "KERNEL IMG"
.LOOP:
push cx
mov cx, 0x000B ; eleven character name
mov si, loc
; image name to find
push di
rep cmpsb ; test for entry match
pop di
;je LOAD_FAT
pop cx
add di, 0x0020 ; queue next directory entry
loop .LOOP
;jmp FAILURE
;Restore text mode
mov ax, 0003h
int 10h
;Return
mov ax, 4c00h
int 21h
;Color
;cX
;cY
;R
drawFilledCircle:
push bp
mov bp, sp
sub sp, 02h
mov cx, WORD [bp+04h] ;R
mov ax, cx
mul ax ;AX = R^2
mov WORD [bp-02h], ax ;[bp-02h] = R^2
mov ax, WORD [bp+06h]
sub ax, cx ;i = cY-R
mov bx, WORD [bp+08h]
sub bx, cx ;j = cX-R
shl cx, 1
mov dx, cx ;DX = Copy of 2R
.advance_v:
push cx
push bx
mov cx, dx
.advance_h:
;Save values
push bx
push ax
push dx
;Compute (i-y) and (j-x)
sub ax, WORD [bp+06h]
sub bx, WORD [bp+08h]
mul ax ;Compute (i-y)^2
push ax
mov ax, bx
mul ax
pop bx ;Compute (j-x)^2 in ax, (i-y)^2 is in bx now
add ax, bx ;(j-x)^2 + (i-y)^2
cmp ax, WORD [bp-02h] ;;(j-x)^2 + (i-y)^2 <= R^2
;Restore values before jump
pop dx
pop ax
pop bx
ja .continue ;Skip pixel if (j-x)^2 + (i-y)^2 > R^2
;Write pixel
push WORD [bp+0ah]
push bx
push ax
call writePx
.continue:
;Advance j
inc bx
loop .advance_h
;Advance i
inc ax
pop bx ;Restore j
pop cx ;Restore counter
loop .advance_v
add sp, 02h
pop bp
ret 08h
;Color
;X
;Y
writePx:
push bp
mov bp, sp
push ax
push bx
mov bx, WORD [bp+04h]
mov ax, bx
shl bx, 6
shl ax, 8
add bx, ax ;320 = 256 + 64
add bx, WORD [bp+06h]
mov ax, WORD [bp+08h]
;TODO: Clip
mov BYTE [es:bx], al
pop bx
pop ax
pop bp
ret 06h
times 510-($-$$) db 0 ; Fill the rest with zeros
dw 0xAA55 ; Boot loader signature
but how do i addmit a text string ?
You've decided to use the 320x200 256 colors video mode 13h.
To output text you can use every BIOS function that deals with text output, just like you would do on a text video screen.
This video mode uses an 8x8 font and so you can position the cursor at any of the 40x25=1000 character cells.
Example of writing a red colored capital B at the center of the screen:
mov dx, 0C14h ;DH=12 row, DL=20 column
mov bh, 0 ;BH=0 display page
mov ah, 02h ;AH=02h set cursor position function
int 10h ;video BIOS interrupt
mov bx, 000Ch ;BH=0 display page, BL=12 red
mov ax, 0E42h ;AH=0Eh teletype function, AL=66 capital B
int 10h ;video BIOS interrupt
BITS 16
[ORG 0x7C00]
;ORG 100h
push 0a000h ;Video memory graphics segment
pop es
mov ax, 0013h ;320x200#8bpp
int 10h
push 0Eh ;Blue
push 10 ;cX
push 10 ;cY
push 10 ;Radius
call drawFilledCircle
push 02h ;Blue
push 40 ;cX
push 40 ;cY
push 30 ;Radius
call drawFilledCircle
push 06h ;Blue
push 140 ;cX
push 100 ;cY
push 70 ;Radius
call drawFilledCircle
;Wait for a key
;xor ah, ah
;int 16h
main: ; Label for the start of the main program
mov ax,0x0000 ; Setup the Data Segment register
; Location of data is DS:Offset
mov ds,ax ; This can not be loaded directly it has to be in two steps.
; 'mov ds, 0x0000' will NOT work due to limitations on the CPU
mov si, HelloWorld ; Load the string into position for the procedure.
call PutStr ; Call/start the procedure
;jmp $ ; Never ending loop
; Procedures
PutStr: ; Procedure label/start
; Set up the registers for the interrupt call
mov ah,0x0E ; The function to display a chacter (teletype)
mov bh,0x00 ; Page number
mov bl,0x07 ; Normal text attribute
.nextchar ; Internal label (needed to loop round for the next character)
lodsb ; I think of this as LOaD String Block
; (Not sure if thats the real meaning though)
; Loads [SI] into AL and increases SI by one
; Check for end of string '0'
or al,al ; Sets the zero flag if al = 0
; (OR outputs 0's where there is a zero bit in the register)
jz .return ; If the zero flag has been set go to the end of the procedure.
; Zero flag gets set when an instruction returns 0 as the answer.
int 0x10 ; Run the BIOS video interrupt
jmp .nextchar ; Loop back round tothe top
.return ; Label at the end to jump to when complete
; ret ; Return to main program
;Wait for a key
xor ah, ah
int 16h
push 01h ;Blue
push 100 ;cX
push 90 ;cY
push 140 ;Radius
call drawFilledCircle
;ret
; Data
HelloWorld db ' WELCOME !! Press Enter ',10,10,0
loc db "KERNEL IMG"
.LOOP:
push cx
mov cx, 0x000B ; eleven character name
mov si, loc
; image name to find
push di
rep cmpsb ; test for entry match
pop di
;je LOAD_FAT
pop cx
add di, 0x0020 ; queue next directory entry
loop .LOOP
;jmp FAILURE
;Restore text mode
mov ax, 0003h
int 10h
;Return
mov ax, 4c00h
int 21h
;Color
;cX
;cY
;R
drawFilledCircle:
push bp
mov bp, sp
sub sp, 02h
mov cx, WORD [bp+04h] ;R
mov ax, cx
mul ax ;AX = R^2
mov WORD [bp-02h], ax ;[bp-02h] = R^2
mov ax, WORD [bp+06h]
sub ax, cx ;i = cY-R
mov bx, WORD [bp+08h]
sub bx, cx ;j = cX-R
shl cx, 1
mov dx, cx ;DX = Copy of 2R
.advance_v:
push cx
push bx
mov cx, dx
.advance_h:
;Save values
push bx
push ax
push dx
;Compute (i-y) and (j-x)
sub ax, WORD [bp+06h]
sub bx, WORD [bp+08h]
mul ax ;Compute (i-y)^2
push ax
mov ax, bx
mul ax
pop bx ;Compute (j-x)^2 in ax, (i-y)^2 is in bx now
add ax, bx ;(j-x)^2 + (i-y)^2
cmp ax, WORD [bp-02h] ;;(j-x)^2 + (i-y)^2 <= R^2
;Restore values before jump
pop dx
pop ax
pop bx
ja .continue ;Skip pixel if (j-x)^2 + (i-y)^2 > R^2
;Write pixel
push WORD [bp+0ah]
push bx
push ax
call writePx
.continue:
;Advance j
inc bx
loop .advance_h
;Advance i
inc ax
pop bx ;Restore j
pop cx ;Restore counter
loop .advance_v
add sp, 02h
pop bp
ret 08h
;Color
;X
;Y
writePx:
push bp
mov bp, sp
push ax
push bx
mov bx, WORD [bp+04h]
mov ax, bx
shl bx, 6
shl ax, 8
add bx, ax ;320 = 256 + 64
add bx, WORD [bp+06h]
mov ax, WORD [bp+08h]
;TODO: Clip
mov BYTE [es:bx], al
pop bx
pop ax
pop bp
ret 06h
times 510-($-$$) db 0 ; Fill the rest with zeros
dw 0xAA55 ; Boot loader signature
I have a small problem.
This is my code:
cmpstr:
pusha
xor cx, cx
mov ax, ds
push ax
mov ax, si
push ax
call strlen
mov dx, ax
mov ax, es
mov ds, ax
mov si, bx
call strlen
cmp al, dl
jnz .fail
pop ax
mov si, ax
pop ax
mov ds, ax
.loop:
push bx
mov al, byte [es:bx]
mov bl, byte [ds:si]
cmp al, bl
jne .fail
cmp bl, 0
jz .suc
pop bx
add bx, 1
inc si
inc cx
jmp .loop
.fail:
mov al, 'C';
mov ah, 0Eh
int 10h
popa
mov ax, 0
jmp .end
.suc:
mov al, 'D';
mov ah, 0Eh
int 10h
popa
mov ax, 1
.end:
ret
This procedure should compare two strings and return (mov to ax) 1, if strings (first on es:bx, second ds:si) are same or 0 if they're different. My problem is that command before procedure call is executed, letter 'D' is being printed (comparasion was successful) but command after procedure call is not working. I think that problem must be somewhere in this procedure. Does anybody know what is wrong here?
When you leave the loop with one of the conditional jumps
.loop:
push bx
mov al, byte [es:bx]
mov bl, byte [ds:si]
cmp al, bl
jne .fail
cmp bl, 0
jz .suc
You have pushed BX, but you never pop it. That will make the next RET go to strange places.
I have writen this little experiement bootstrap that has a getline and print_string "functions". The boot stuff is taken from MikeOS tutorial but the rest I have writen myself. I compile this with NASM and run it in QEMU.
So the actual question: I've declared this variable curInpLn on line 6. What ever the user types is saved on that variable and then after enter is hit it is displayed to the user with some additional messages. What I'd like to do is to clear the contents of curInpLn each time the getline function is called but for some reason I can't manage to do that. I'm quite the beginner with Assmebly at the moment.
You can compile the code to bin format and then create a floppy image of it with: "dd status=noxfer conv=notrunc if=FILENAME.bin of=FILENAME.flp" and run it in qemu with: "qemu -fda FILENAME.flp"
BITS 16
jmp start
welcomeSTR: db 'Welcome!',0
promptSTR: db 'Please prompt something: ',0
responseSTR: db 'You prompted: ',0
curInpLn: times 80 db 0 ;this is a variable to hold the input 'command'
curCharCnt: dw 0
curLnNum: dw 1
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
mov sp, 4096
mov ax, 07C0h ; Set data segment to where we're loaded
mov ds, ax
call clear_screen
lea bx, [welcomeSTR] ; Put string position into SI
call print_string
call new_line
.waitCMD:
lea bx, [promptSTR]
call print_string
call getLine ; Call our string-printing routine
jmp .waitCMD
getLine:
cld
mov cx, 80 ;number of loops for loopne
mov di, 0 ;offset to bx
lea bx, [curInpLn] ;the address of our string
.gtlLoop:
mov ah, 00h ;This is an bios interrupt to
int 16h ;wait for a keypress and save it to al
cmp al, 08h ;see if backspace was pressed
je .gtlRemChar ;if so, jump
mov [bx+di], al ;effective address of our curInpLn string
inc di ;is saved in bx, di is an offset where we will
;insert our char in al
cmp al, 0Dh ;see if character typed is car-return (enter)
je .gtlDone ;if so, jump
mov ah, 0Eh ;bios interrupt to show the char in al
int 10h
.gtlCont:
loopne .gtlLoop ;loopne loops until cx is zero
jmp .gtlDone
.gtlRemChar:
;mov [bx][di-1], 0 ;this needs to be solved. NASM gives error on this.
dec di
jmp .gtlCont
.gtlDone:
call new_line
lea bx, [responseSTR]
call print_string
mov [curCharCnt], di ;save the amount of chars entered to a var
lea bx, [curInpLn]
call print_string
call new_line
ret
print_string: ; Routine: output string in SI to screen
mov si, bx
mov ah, 0Eh ; int 10h 'print char' function
.repeat:
lodsb ; Get character from string
cmp al, 0
je .done ; If char is zero, end of string
int 10h ; Otherwise, print it
jmp .repeat
.done:
ret
new_line:
mov ax, [curLnNum]
inc ax
mov [curLnNum], ax
mov ah, 02h
mov dl, 0
mov dh, [curLnNum]
int 10h
ret
clear_screen:
push ax
mov ax, 3
int 10h
pop ax
ret
times 510-($-$$) db 0 ; Pad remainder of boot sector with 0s
dw 0xAA55 ; The standard PC boot signature
I haven't written code in Assembly for 20 years (!), but it looks like you need to use the 'stosw' instruction (or 'stosb'). STOSB loads the value held in AL to the byte pointed to by ES:DI, whereas STOSSW loads the value held in AX to the word pointed to by ES:DI. The instruction automatically advances the pointer. As your variable curInpLn is 80 bytes long, you can clear it with 40 iterations of STOSW. Something like
xor ax, ax ; ax = 0
mov es, ds ; point es to our data segment
mov di, offset curInpLn ; point di at the variable
mov cx, 40 ; how many repetitions
rep stosw ; zap the variable
This method is probably the quickest method of clearing the variable as it doesn't require the CPU to retrieve any instructions from the pre-fetch queue. In fact, it allows the pre-fetch queue to fill up, thus allowing any following instructions to execute as quickly as possible.