Hello. I issued the command
nasm -f bin -o a_very_simple_os.bin a_very_simple_os.asm
to create an OS with the following Assembly code:
======================================
; A Very Simple Kernel For A Very Simple OS!
; By Pietro Gagliardi
%DEFINE NL 13, 10
[ORG 0x7C00]
[BITS 32]
SEGMENT .DATA
COLOR DW 0x0F
MESG1 DB "Welcome to ", 0
MESG2 DB "A ", 0
MESG3 DB "Very ", 0
MESG4 DB "Simple ", 0
MESG5 DB "Operating ", 0
MESG6 DB "System", 0
MESG7 DB "!", NL, 0
MESG8 DB "This is a very simple OS!", NL, 0
MESG9 DB "Hit Ctrl+Alt+Del to restart the computer.", NL, 0
XPOS DB 0
YPOS DB 0
SEGMENT .TEXT
GLOBAL makevid
GLOBAL main
GLOBAL halt
GLOBAL printmsg1
GLOBAL printmsg2
GLOBAL printmsg3
GLOBAL printmsg4
GLOBAL printmsg5
GLOBAL printmsg6
GLOBAL printmsg7
GLOBAL printmsg8
GLOBAL printmsg9
GLOBAL println
GLOBAL setcolor
GLOBAL dochar
GLOBAL cprint
GLOBAL sprint
JMP main ; BEGIN THE OS!
halt:
JMP halt
setcolor:
MOV AH, [COLOR]
RET
main:
CALL makevid
CALL setcolor
CALL printmsg1
MOV WORD [COLOR], 0x0B
CALL printmsg2
MOV WORD [COLOR], 0x5E
CALL printmsg3
MOV WORD [COLOR], 0x19
CALL printmsg4
MOV WORD [COLOR]. 0x6F
CALL printmsg5
MOV WORD [COLOR], 0xF0
CALL printmsg6
MOV WORD [COLOR], 0x5C
CALL printmsg7
MOV WORD [COLOR], 0x0F
CALL printmsg8
CALL printmsg9
JMP halt
makevid:
XOR AX, AX
MOV DS, AX
MOV SS, AX
MOV SP, 0x9C00
MOV AX, 0xB800
MOV ES, AX
RET
printmsg1:
MOV SI, MESG1
CALL sprint
RET
printmsg2:
MOV SI, MESG2
CALL sprint
RET
printmsg3:
MOV SI, MESG3
CALL sprint
RET
printmsg4:
MOV SI, MESG4
CALL sprint
RET
printmsg5:
MOV SI, MESG5
CALL sprint
RET
printmsg6:
MOV SI, MESG6
CALL sprint
RET
printmsg7:
MOV SI, MESG7
CALL sprint
RET
printmsg8:
MOV SI, MESG8
CALL sprint
RET
printmsg9:
MOV SI, MESG9
CALL sprint
RET
sprint:
LODSB
CMP AL, 0
JNE dochar
ADD BYTE [YPOS], 1
MOV BYTE [XPOS], 0
RET
dochar:
CALL cprint
cprint:
MOV CX, AX
MOVZX AX, BYTE [YPOS]
MOV DX, 160
MUL DX
MOVZX BX, BYTE [XPOS]
SHL BX, 1
MOV DI, 0
ADD DI, AX
ADD DI, BX
MOV AX, CX
STOSW
ADD BYTE [XPOS], 1
RET
TIMES 510-($-$$) DB 0
DB 0x55
DB 0xAA
======================================
For some reason, the .bin file comes out 620K. Without the TIMES statement, it is less than 300K. I need it to be exactly 512K. What am I doing wrong?