0

So i am basically making a basic commandline os and i have made it so that it can take keyboard presses and a procedure to go to a new line when i press enter but i want it to store the command as a string before moving to a new line so that i can compare a command with the user input so that I can make it print a string or do something so how would we join all the chars and make a string here is my code till now

;bg
MOV AH, 06h   
XOR AL, AL    
XOR CX, CX    
MOV DX, 184FH  
MOV BH, 1Eh  
INT 10H
;cursor
mov dh, 1
mov dl, 30
mov bh, 0
mov ah, 2
int 10h
;text
mov ah, 0x0E
mov al, 'W'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'E'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'L'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'C'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'O'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'M'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'E'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, ' '
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'T'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'O'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, ' '
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'D'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'A'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'R'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'S'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'H'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'O'
mov bh, 0x00
int 10h
mov ah, 0x0E
mov al, 'S'
mov bh, 0x00
int 10h
;cursor
mov dh, 3
mov dl, 2
mov bh, 0
mov ah, 2
int 10h
;commandline
Key:
    MOV AH,0 
    INT 16H
    cmp ah, 28
    je Newline
    mov ah, 0eh
    int 10h
    jmp Key

Newline:

    add dh, 1
    mov dl, 2
    mov bh, 0
    mov ah, 2
    int 10h
    jmp Key
times 510-($-$$) db 0
dw 0xaa55

Screenshot: img of the program

1 Answers1

2

As a first observation, you are writing all of this in a bootsector. That's probably fine for learning purposes, but then at least be conscious about a bootsector's 512 bytes size limitation. I mean, you should not output all of those characters separately but rather as a string, which is of course what your question is about, isn't it.

First solve the output, the input storage problem is similar.

Start your bootsector program with this code:

ORG  7C00h
xor  ax, ax
mov  ds, ax
mov  es, ax
cld

Near the bottom of the program you insert this text:

msg  db 'WELCOME TO DARSHOS', 0
times 510-($-$$) db 0
dw 0xAA55

And where you have that very long chain of single character outputs, you replace the whole chain by the following:

;text
  mov  si, msg     ; Load address of the message in SI 
  mov  bh, 0       ; DisplayPage
  lodsb
More:
  mov  ah, 0Eh     ; BIOS.Teletype
  int  10h
  lodsb            ; Retrieve a character, auto-increments the address SI
  cmp  al, 0
  jnz  More

If your assembler follows NASM style, mov si, msg loads the address of the message. But if your assembler follows MASM style, you will have to write mov si, offset msg instead.


In order to save the inputted characters, you need to define a suitable buffer.
The buf line below will allow for a textual command of at most 7 characters followed by the delimiting carriage return. You need the delimiter to later know how long the full command is. Insert the following line near the bottom of the program:

buf  db '........'
msg  db 'WELCOME TO DARSHOS', 0
times 510-($-$$) db 0
dw 0xAA55

And this is how you fill it:

;commandline
Key:
    mov  di, buf   ; Load address of the buffer in DI
Next:
    mov  ah, 00h   ; BIOS.GetKeyboardKey
    int  16h       ; -> AX
    stosb          ; Store in buffer, auto-increments the address DI
    mov  bh, 0     ; DisplayPage
    mov  ah, 0Eh   ; BIOS.Teletype
    int  10h
    cmp  al, 13
    jne  Next      ; Not yet carriage return
    mov  al, 10    ; Let follow a linefeed to complete the 'newline' sequence
    int  10h
    ...

And at the ... you can start processing the string of characters that form a command like CLS, TIME, or anything that suits you.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • thank you for your response , i did what you said but do i then compare the text inputted with the command i want like '--help or --cls' i tried using cmp but it gave an error 'incorrect optcode and opreands' on the line plese help me i am really new to asm and osdev – Darsh Cubing Sep 14 '21 at 05:24
  • also how to get more data space as you said you can only have 512 bytes of code in a bootsector – Darsh Cubing Sep 14 '21 at 05:34
  • @DarshCubing The size of the bootsector is fixed, but the trick is to fill the bootsector with a **bootloader program**. That is code whose only job it is to load the rest of your OS from the disk. You can find an example in this answer https://stackoverflow.com/questions/34216893/disk-read-error-while-loading-sectors-into-memory/34382681#34382681. It is definitely not a trivial undertaking to get it right! If learning the assembly language is what you really want, then maybe consider writing .COM programs instead of the much harder OS development... – Sep Roland Sep 15 '21 at 23:11
  • thanks for the reply i posted the question please take a look at it: https://stackoverflow.com/questions/69202323/comparing-the-freshly-inputted-text-to-a-list-of-available-commands-in-asm – Darsh Cubing Sep 16 '21 at 04:27