Hey guys, I am from Jinx, and no one there knows ASM, I am part of a project to design a console based oeprating system in QBasic, we have gone through numerous converters and decompilers to turn our QB code into asm 286. I would like to be sure that the code works, I am not asking you to compile it or to even be thourough. I just want someone to take a quick peak at the code and tell me if it seems functional. I would be very indebted to you if you did this for me.
;Credits:
;BASM v3.0, .bas to .asm converter
;FirstBasic, BASIC Debugger
;TedFelix.com, Teching me how to code in QBasic
;Linus Torvalds, Inspiring me to want to make an free OS
;Mark Overmars, Getting me interested in programming in the first place
.286p
MaxString Equ 81
Code Segment Byte Public
Code Ends
Data Segment Word Public
Data Ends
Stak Segment Word Stack
DW 128 DUP (?)
Stak Ends
Dummy Segment Para Public
Dummy Ends
Code Segment
Assume CS:Code,DS:Data,ES:Nothing,SS:Stak
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
; Release Unused Memory
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Mov BX,Seg Data
Mov DS,BX ;Set data segment
Mov BX,Seg Dummy ;End of pgm
Mov AX,CS ;Start of pgm
Sub BX,AX ;Calc pgm size
Add BX,16 ;Paragraphs in Stack + 1
Mov AH,4AH ;Shrink mem
Int 21h ;Thru Dos
Push DS
Pop AX
Mov ES,AX ;Set ES to DS
Mov DefSeg,AX ;Set DefSeg to DS
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Call GetCursor
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
; ;Translation begins
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
;
;cls
;
Call Cls
;
;print "Welcome to Basic-OS"
;
Mov SI,Offset $tring_01
Call PrintStr
Call SetCursor
Call DoCrLf
;
;print "The folllowing is a list of supported commands:"
;
Mov SI,Offset $tring_02
Call PrintStr
Call SetCursor
Call DoCrLf
;
;print "1-----------Displays this list"
;
Mov SI,Offset $tring_03
Call PrintStr
Call SetCursor
Call DoCrLf
;
;print "2-------Brings up a calculator"
;
Mov SI,Offset $tring_04
Call PrintStr
Call SetCursor
Call DoCrLf
;
;print "3----Clears the current screen"
;
Mov SI,Offset $tring_05
Call PrintStr
Call SetCursor
Call DoCrLf
;
;IF a = 1 then
;
Cmp A,1
Je $+5
Jmp _EndIf_01
;
;print "1-----------Displays this list"
;
Mov SI,Offset $tring_03
Call PrintStr
Call SetCursor
Call DoCrLf
;
;print "2-------Brings up a calculator"
;
Mov SI,Offset $tring_04
Call PrintStr
Call SetCursor
Call DoCrLf
;
;print "3----Clears the current screen"
;
Mov SI,Offset $tring_05
Call PrintStr
Call SetCursor
Call DoCrLf
;
;goto 1
;
Jmp 1
;
;end if
;
_EndIf_01:
;
;IF a = 2 then
;
Cmp A,2
Je $+5
Jmp _EndIf_02
;
;INPUT "Enter first number " b
;
Mov SI,Offset $tring_08
Call PrintStr
Call KBInput
Mov DI,Offset $_0_
Call Val
Mov B,AX
;
;INPUT "Enter second number " c
;
Mov SI,Offset $tring_10
Call PrintStr
Call KBInput
Mov DI,Offset $_0_
Call Val
Mov C,AX
;
;PRINT "Addition answer for these numbers is " b + c
;
Mov SI,Offset $tring_12
Call PrintStr
Call SetCursor
Mov AX,B
Call Printnum
Mov AX,+
Call Printnum
Mov AX,C
Call Printnum
Call DoCrLf
;
;PRINT "Subtraction answer for these numbers is " b - c
;
Mov SI,Offset $tring_13
Call PrintStr
Call SetCursor
Mov AX,B
Call Printnum
Mov AX,-
Call Printnum
Mov AX,C
Call Printnum
Call DoCrLf
;
;PRINT "Division answer for these numbers is " b / c
;
Mov SI,Offset $tring_14
Call PrintStr
Call SetCursor
Mov AX,B
Call Printnum
Mov AX,/
Call Printnum
Mov AX,C
Call Printnum
Call DoCrLf
;
;PRINT "Multiplication answer for these numbers is " b * c
;
Mov SI,Offset $tring_15
Call PrintStr
Call SetCursor
Mov AX,B
Call Printnum
Mov AX,*
Call Printnum
Mov AX,C
Call Printnum
Call DoCrLf
;
;goto 1
;
Jmp 1
;
;end if
;
_EndIf_02:
;
;if a = 3 then
;
Cmp A,3
Je $+5
Jmp _EndIf_03
;
;cls
;
Call Cls
;
;goto 1
;
Jmp 1
;
;end if
;
_EndIf_03:
;
;print "Invalid command"
;
Mov SI,Offset $tring_16
Call PrintStr
Call SetCursor
Call DoCrLf
;
;goto 1
;
Jmp 1
ExitToDos:
Mov AH,4Ch
Xor AL,AL
Int 21h
GetCursor Proc Near
Mov AH,3
Xor BH,BH
Int 10h
Xor AX,AX
Mov AL,DL
Inc AL
Mov $Xcur,AX
Mov AL,DH
Inc AL
Mov $Ycur,AX
Ret
GetCursor Endp
SetCursor Proc Near
Mov AX,$Xcur
Mov DL,AL
Dec DL
Mov AX,$Ycur
Mov DH,AL
Dec DH
Mov AH,2
Int 10h
Ret
SetCursor Endp
MoveStr Proc Near
Cld
MoveStr1:
Lodsb
Stosb
Or AL,AL
Jnz MoveStr1
Ret
MoveStr Endp
Len Proc Near
Push CX
Push SI
Push DI
Mov DI,SI
Xor AL,AL
Mov CX,0ffffh
Cld
Repnz Scasb
Not CX
Dec CX
Mov AX,CX
Pop DI
Pop SI
Pop CX
Ret
Len Endp
Val Proc Near
Xor BX,BX
Mov $Var1,BX
Mov SI,BX
Mov CX,1
ValLp:
Mov AX,[DI]
Xor AH,AH
Cmp AL,AH
Je ValPop
Cmp AL,48
Jb ValBadChr
Cmp AL,57
Jg ValBadChr
Sub AL,'0'
Push AX
Inc SI
ValBadChr:
Cmp AL,45
Jne ValMore
Mov $Var1,1
ValMore:
Inc DI
Jmp ValLp
ValPop:
Cmp SI,0
Je ValNil
Pop AX
Mul CX
Add BX,AX
Mov AX,CX
Mov CX,10
Mul CX
Mov CX,AX
Dec SI
Cmp SI,1
Jge ValPop
Mov AX,BX
Jmp ValExit
ValNil:
Xor AX,AX
ValExit:
Cmp $Var1,1
Jne Valgone
Neg AX
Valgone:
Ret
Val Endp
Str$ Proc Near
Cmp BX,1
Je SkipPad
Mov [DI],Byte Ptr 32
Inc DI
SkipPad:
Xor BX,BX
Cmp AX,32768
Jb NumIsPos
Neg AX
Mov [DI],Byte Ptr '-'
Inc DI
NumIsPos:
Xor CX,CX
Mov BX,10
StrMore:
Inc CX
Xor DX,DX
Div BX
Push DX
Cmp AX,0
Jne StrMore
EmitDgt:
Pop AX
Add AL,'0'
Mov [DI],AL
Inc DI
Loop EmitDgt
Xor AX,AX
Mov [DI],AL
Ret
Str$ Endp
PrintNum Proc Near
Mov DI,Offset $_1_
Xor BX,BX
Call Str$
Mov SI,Offset $_1_
Call PrintStr
Call SetCursor
Ret
PrintNum Endp
Cls Proc Near
Push BP
Mov AH,0Fh
Int 10h
Cmp AL,4
Je ClsGraphics
Cmp AL,0dh
Je ClsGraphics
Cmp AL,0eh
Je ClsGraphics
Cmp AL,10h
Je ClsGraphics
Cmp AL,0fh
Je ClsGraphics
Cmp AL,11h
Je ClsGraphics
Cmp AL,12h
Je ClsGraphics
Cmp AL,13h
Je ClsGraphics
Mov AH,06
Xor AL,AL
Mov BX,$Attr
Mov BH,BL
Xor CX,CX
Mov DH,24
Mov DL,79
Int 10h
Xor BX,BX
Xor DX,DX
Mov AH,02
Int 10h
Mov $Xcur,1
Mov $Ycur,1
Jmp ClsEnd
ClsGraphics:
Mov $Xcur,1
Mov $Ycur,1
Mov BX,BgColor
Xchg BH,BL
Xor CX,CX
Mov DL,79
Mov DH,43
Mov AX,0600h
Int 10h
ClsEnd:
Pop BP
Ret
Cls Endp
PrintStr Proc Near
Call Len
Push AX
Mov CX,AX
Cmp CX,0
Jle PS_3
Mov BX,$Attr
Mov AX,$Ycur
Mov DI,$Xcur
Push DS
Push ES
Dec AX
Dec DI
Cmp DI,0
Jg PS_1
Xor DI,DI
PS_1:
Mov DX,80
Mul DX
Add DI,AX
Shl DI,1
Mov AX,0B000H
Mov ES,AX
Mov AH,0FH
Int 10H
Cmp AL,07H
Je PS_2
Mov AX,0B800H
Mov ES,AX
PS_2:
Cld
Movsb
Mov ES:[DI],BL
Inc DI
Loop PS_2
Pop ES
Pop DS
PS_3:
Pop AX
Add $Xcur,AX
Ret
PrintStr Endp
DoCrLf Proc Near
Mov $Xcur,1
Inc $Ycur
Cmp $Ycur,26
Jne CrLf_1
Dec $Ycur
CrLf_1:
Mov DX,Offset $CrLf
Mov AH,9
Int 21h
Mov BX,$Xcur
Mov DL,BL
Dec DL
Mov BX,$Ycur
Mov DH,BL
Dec DH
Xor BX,BX
Mov AH,2
Int 10h
Ret
DoCrLf Endp
kbInput Proc Near
Mov AX,$Xcur
Mov $Var1,AX
Mov AX,$Ycur
Mov $Var2,AX
Call SetCursor
Mov BX,0
Mov CX,255
Mov DX,Offset $_0_
Mov AH,3fh
Int 21h
Mov $Var3,AX
Mov SI,Offset $_0_
Dec SI
KBFindCR:
Inc SI
Mov AL,ES:[SI]
Cmp AL,13
Jne KBFindCR
Xor AX,AX
Mov ES:[SI],AL
Call GetCursor
Ret
kbInput Endp
Code Ends
Data Segment
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ System Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
$Xcur DW 1
$Ycur DW 1
$Attr DW 7
$CrLf DB 13,10,'$'
FgColor DW 7
BgColor DW 0
Err DW 0
DefSeg DW 0
$Var0 DW 0
$Var1 DW 0
$Var2 DW 0
$Var3 DW 0
$Var4 DW 0
$Var5 DW 0
$Var6 DW 0
$Var7 DW 0
$Var8 DW 0
$Var9 DW 0
$Var10 DW 0
$Var11 DW 0
$Var12 DW 0
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Users Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
$tring_01 DB "Welcome to Basic-OS",0
$tring_02 DB "The folllowing is a list of supported commands:",0
$tring_03 DB "1-----------Displays this list",0
$tring_04 DB "2-------Brings up a calculator",0
$tring_05 DB "3----Clears the current screen",0
$tring_06 DB "> ",0
A DW 0
$tring_08 DB "Enter first number ",0
B DW 0
$tring_10 DB "Enter second number ",0
C DW 0
$tring_12 DB "Addition answer for these numbers is ",0
$tring_13 DB "Subtraction answer for these numbers is ",0
$tring_14 DB "Division answer for these numbers is ",0
$tring_15 DB "Multiplication answer for these numbers is ",0
$tring_16 DB "Invalid command",0
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ System Un-Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
$_0_ DB MaxString DUP(?)
$_1_ DB MaxString DUP(?)
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Users Un-Initialized Data ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
;ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Data Ends
End
20 people have read this an no one has replied, so I will
The basic fact is: No
Here are the reasons:
1. This code uses Interrupt 21h which requires DOS.
2. The program you are using didn't correctly convert your code here:
;PRINT "Addition answer for these numbers is " b * c
Mov AX,/
Call Printnum
That is actually the first place off the top of my head that the assembler would show errors.
Now, here is the bad news. QBasic Code + BASM will never be able to write an Operating System
Operating Systems don't all have to be complex, but the basic fact is you _MUST_ have some knowledge of x86 software creation at low levels before it would ever be possible to do this.
I have been seeing attempts to do this sort of thing for years, and parts of the code above even look familiar. The main problem is that QBasic depends on an underlying OS and cannot operate without it, and the same goes for any code developed from QBasic. The attachment is a DOS program that executes QBasic and records and displays the total number of interrupt 21h calls, and the function number of the called functions. If you simply close the welcome dialog and exit, QBasic makes (directly or indirectly) 127 interrupt 21h calls to 12 functions. If you close the welcome dialog, enter the following source, save it, and run it before exiting, QBasic makes 338 interrupt 21h calls to 26 functions. The program determines the function number from the value in AH, so it cannot differentiate sub-functions, so the number of individual functions called is probably somewhat higher.
OPEN "monitor.asm" FOR INPUT AS 1
WHILE NOT EOF(1)
LINE INPUT #1, a$
PRINT a$
WEND
[attachment deleted by admin]