0

Hello,
I'm beginning in the OS development(In Assembly, Nasm as Assembler) and i need to implement a command-line on it, but i don't know how to do this, but what i want to say as command-line is like MS-DOS or UNIX:

> ver
BerlOS v.0.0.1
> _

But i don't know how to do the input method(ver in the command). In the repetition of the > before the user input things i know, i only need to do a JMP to the section that prints the > and the input method, if it's needed, here is my code:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors per FAT
SectorsPerTrack     dw 18           ; Sectors per track (36/cylinder)
Sides               dw 2            ; Number of sides/heads
HiddenSectors       dd 0            ; Number of hidden sectors
LargeSectors        dd 0            ; Number of LBA sectors
DriveNo             dw 0            ; Drive No: 0
Signature           db 41           ; Drive signature: 41 for floppy
VolumeID            dd 00000000h    ; Volume ID: any number
VolumeLabel         db "BERL OS"    ; Volume Label: any 11 chars
FileSystem          db "FAT12"      ; File system type: don't change!

; End of the disk description table
; ------------------------------------------------------------------

main:
MOV BX, 0                           ; Disable blinking.
MOV BH, 00h
MOV BL, 07h                         ; Color settings
MOV AL, 1
MOV BH, 0
MOV BL, 02h
MOV CX, osmsgend - os_msg           ; Calculate message size. 
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel

wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 059 
MOV CX, welcome_end - welcome       ; Calculate message size. 
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP osmsgend
                         
welcome DB "Welcome !"
welcome_end:
                         
os_msg DB "BerlOS v0.0.1"
osmsgend:
JMP $

; Boot things
TIMES 510-($-$$) DB 0	            ; Fill the rest of the sector with zeros
DW 0xAA55		                    ; Boot signature

The only thing that i need too know how to do is the input characters method.

Thanks,
Nathan Paulino Campos

2
Contributors
16
Replies
17
Views
7 Years
Discussion Span
Last Post by Nathan Campos
0

You're using the 0x10 VIDEO BIOS services handler for your video handling so use the 0x16 KEYBOARD BIOS services handler for your keyboard handling!

; Get Keyboard value (and wait for press)
  mov ah,0
  int 16h   ; KEYBOARD
      ;ah=scan code   al=ASCII character
0

Hello wildgoose,
Thanks for your help, now i know that INT 16h is for keyboard, but if i want to improve like, the user types: ver , then when he press enter the OS shows a message, like: ver DB "ver. 0.0.1" .

Thanks,
Nathan Paulino Campos

0

After data entry, remove carriage return and set a terminator!

Create a master list of commands! A table lookup of string addresses and scan through the list one at a time and do a caseless string to data entered. When you find a caseless match you have your command. Then jump to the code to handle that command!

You could use a structure table that contains the pointer to the string, and address of the function.


Initially just write a string compare function and do a series of if-then's to find your matching string!

0

But how i can do this?
Sorry about this simple questions, but i'm learning Assembly for OS's.

Thanks for you attention!

0

One step at a time

xVer  db   'Ver',0
Key   db    dup(128)
Kscan  db    dup(128)


  xor bx,bx

KeyIn:
  mov ah,0
  int 16h   ; KEYBOARD
      ;ah=scan code   al=ASCII character

  mov Key[ bx ],al
   mov KScan[ bx ],ah
   inc bx
   cmp al,0dh     ; Carriage return
   jne  KeyIn

      ; bx = buffer Length
   mov Key[ bx - 1 ],0           ; Overwrite with terminator

      ; String now in buffer

Visually inspect buffer to make sure the string is there intact!

Then work on a string compare function

mov ax,offset KeyBuf
   mov dx,offset xVer
   call StrICmp
   jnc  next

   ;;; Have a match!
   jmp done

next:

done:
0

Ok, i'm going to try, any thing i will post, but i know that i will not have problems, thanks!

0

If it's needed, here is the code:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors per FAT
SectorsPerTrack     dw 18           ; Sectors per track (36/cylinder)
Sides               dw 2            ; Number of sides/heads
HiddenSectors       dd 0            ; Number of hidden sectors
LargeSectors        dd 0            ; Number of LBA sectors
DriveNo             dw 0            ; Drive No: 0
Signature           db 41           ; Drive signature: 41 for floppy
VolumeID            dd 00000000h    ; Volume ID: any number
VolumeLabel         db "BERL OS"    ; Volume Label: any 11 chars
FileSystem          db "FAT12"      ; File system type: don't change!

; End of the disk description table
; ------------------------------------------------------------------

main:
MOV BX, 0                           ; Disable blinking.
MOV BH, 00h
MOV BL, 07h                         ; Color settings
MOV AL, 1
MOV BH, 0
MOV BL, 02h
MOV CX, osmsgend - os_msg           ; Calculate message size. 
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel

wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 059 
MOV CX, welcome_end - welcome       ; Calculate message size. 
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP KeyIn

; ------------------------------------------
; Keyboard input method
xVer  db   'Ver', 0
Key   db    dup(128)
Kscan  db    dup(128)


  xor bx,bx

KeyIn:
  mov ah,0
  int 16h   ; KEYBOARD
      ;ah=scan code   al=ASCII character

  mov Key[ bx ],al
   mov KScan[ bx ],ah
   inc bx
   cmp al,0dh     ; Carriage return
   jne  KeyIn

      ; bx = buffer Length
   mov Key[ bx - 1 ],0           ; Overwrite with terminator

      ; String now in buffer
   mov ax,offset KeyBuf
   mov dx,offset xVer
   call StrICmp
JMP osmsgend

; End of input characters method
; ------------------------------------------

                         
welcome DB "Welcome !"
welcome_end:
                         
os_msg DB "BerlOS v0.0.1"
osmsgend:
JMP $

; Boot things
TIMES 510-($-$$) DB 0	            ; Fill the rest of the sector with zeros
DW 0xAA55		                    ; Boot signature

Thanks!

0

Look at the line number that contains the error and look for things.


Line#35
You may need the label on the same line as instruction. Some assemblers require this, some don't!

main: MOV BX, 0 ; Disable blinking.

Line#70 and #71
;Key db dup(128)
;Kscan db dup(128)
Key db 128 dup(?)
Kscan db 128 dup(?)

Line#81,82 should then be fixed.

Line#88 mov byte ptr Key[ bx - 1 ],0 ; Overwrite with
terminator

Wrong label name
mov ax,offset Key

Don't know about 92
mov dx,offset xVer

0

Thanks, but i'm getting the same errors, when i try to compile with all the fixes, remember that i'm using Nasm as compiler.

0

Here is the log of the compiler:

C:\Users\Nathan\Desktop>nasm os.asm
os.asm:70: error: comma expected after operand 1
os.asm:71: error: comma expected after operand 1
os.asm:81: error: comma, colon or end of line expected
os.asm:82: error: comma, colon or end of line expected
os.asm:88: error: comma, colon or end of line expected
os.asm:91: error: comma, colon or end of line expected
os.asm:92: error: comma, colon or end of line expected

What is wrong?

0

And here is the code modified:

[BITS 16]	     ; 16 bit code generation
[ORG 0x7C00]	 ; ORGin location is 7C00

JMP short main   ; Jump past disk description section
NOP              ; Pad out before disk description

; ------------------------------------------------------------------
; Disk description table, to make it a valid floppy
; Note: some of these values are hard-coded in the source!
; Values are those used by IBM for 1.44 MB, 3.5" diskette

OEMLabel            db "BERL OS"    ; Disk label - 8 chars
BytesPerSector      dw 512          ; Bytes per sector
SectorsPerCluster   db 1            ; Sectors per cluster
ReservedForBoot     dw 1            ; Reserved sectors for boot record
NumberOfFats        db 2            ; Number of copies of the FAT
RootDirEntries      dw 224          ; Number of entries in root dir
LogicalSectors      dw 2880         ; Number of logical sectors
MediumByte          db 0F0h         ; Medium descriptor byte
SectorsPerFat       dw 9            ; Sectors per FAT
SectorsPerTrack     dw 18           ; Sectors per track (36/cylinder)
Sides               dw 2            ; Number of sides/heads
HiddenSectors       dd 0            ; Number of hidden sectors
LargeSectors        dd 0            ; Number of LBA sectors
DriveNo             dw 0            ; Drive No: 0
Signature           db 41           ; Drive signature: 41 for floppy
VolumeID            dd 00000000h    ; Volume ID: any number
VolumeLabel         db "BERL OS"    ; Volume Label: any 11 chars
FileSystem          db "FAT12"      ; File system type: don't change!

; End of the disk description table
; ------------------------------------------------------------------

main:
MOV BX, 0                           ; Disable blinking.
MOV BH, 00h
MOV BL, 07h                         ; Color settings
MOV AL, 1
MOV BH, 0
MOV BL, 02h
MOV CX, osmsgend - os_msg           ; Calculate message size. 
MOV DL, 30
MOV DH, 0
PUSH CS
POP ES
MOV BP, os_msg
MOV AH, 13h
INT 10h
JMP wel

wel:
MOV BH, 00h
MOV BL, 07h
MOV AL, 1
MOV BH, 0
MOV BL, 059 
MOV CX, welcome_end - welcome       ; Calculate message size. 
MOV DL, 32
MOV DH, 2
PUSH CS
POP ES
MOV BP, welcome
MOV AH, 13h
INT 10h
JMP KeyIn

; ------------------------------------------
; Keyboard input method
xVer  db   'Ver', 0
Key   db  128  dup(?)
Kscan db  128  dup(?)


  xor bx,bx

KeyIn:
  mov ah,0
  int 16h   ; KEYBOARD
	  ;ah=scan code   al=ASCII character

  mov Key[ bx ],al
   mov KScan[ bx ],ah
   inc bx
   cmp al,0dh     ; Carriage return
   jne  KeyIn

	  ; bx = buffer Length
   mov byte ptr Key[ bx - 1 ], 0           ; Overwrite with terminator

	  ; String now in buffer
   mov ax,offset KeyBuf
   mov dx,offset xVer
   call StrICmp
JMP osmsgend

; End of input characters method
; ------------------------------------------


welcome DB "Welcome !"
welcome_end:

os_msg DB "BerlOS v0.0.1"
osmsgend:
JMP $

; Boot things
TIMES 510-($-$$) DB 0	            ; Fill the rest of the sector with zeros
DW 0xAA55		                    ; Boot signature
0

I definitely don't like NASM!
It has its own way of doing things....

; ------------------------------------------
; Keyboard input method
xVer:  db   'Ver',0

Key:  	times	128 db 0		; reserve 128 byte Keyboard
KScan:	times   128 db 0		; reserve 128 byte scan

;	______________
;	Keyboard Input

KeyIn:
	xor bx,bx

KeyIn0:
	mov ah,0
	int 16h				; KEYBOARD
      ;ah=scan code   al=ASCII character

	mov [Key+bx],al
	mov [KScan+bx],ah
	inc bx
	cmp al,0dh     ; Carriage return
	jne  KeyIn0

      ; bx = buffer Length
	mov word [Key + bx - 1],0           ; Overwrite with terminator

	; String now in buffer
	mov ax,Key
	mov dx,xVer

	call StrICmp

	JMP osmsgend



; End of input characters method
; ------------------------------------------


StrICmp
	stc
	ret
0

Thanks very much wildgoose!
You are a very nice and (the word that say that the person helps many people, because i don't know, remember that i live in Brazil).

God bless you my friend!

0

That terminator should have been someting like...

mov byte [Key + bx - 1],0           ; Overwrite with terminator

It's an 8-bit terminator not 16-bit.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.