flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 03 Sep 2011, 04:10
Moved to DOS forum.
|
|||
![]() |
|
typedef 03 Sep 2011, 06:15
Here's a little something
CS/DS:80h = Argument count CS/DS:81h = Space between arguments and COM file path. CS/DS:82h = Start of arguments So the thing is to get the count Code: org 100h ;first of all, get the length of commandline params xor ax,ax mov si,80h lodsb ;AL = Count, now check if there are any test al,al jz no_params xor cx,cx mov cl,al ;else display them mov si,string+26 call prints lea si, [DS:81h] ;<----- Notice 81h not 82h call prints_cnt jmp ok no_params: mov si,string call prints ok: xor ax,ax int 16h ret string db 'No parameters specified !',0 db 'Here are your parameters: ',13,10,0 ; ; Uses count prints_cnt: ;using cl as counter push cx get: pop cx cmp cl,-1 je done_get dec cl push cx lodsb mov dl,al call printc jmp get done_get: ret ; ; dl = Character printc: mov ah,02 int 21h ret ; SI = string pointer prints: A: lodsb test al,al jz done mov dl,al call printc jmp A done: ret |
|||
![]() |
|
Overflowz 03 Sep 2011, 13:08
try BIOS interrupts instead ?
![]() |
|||
![]() |
|
me239 04 Sep 2011, 06:09
Use DOS function 40h and find the length of the string.
Code: org 100h start: mov si, msg call lenstr mov ah, 40h mov bx, 1 mov dx, si int 21h int 20h msg db 'Hello!', 0 lenstr: push si xor cx, cx @@: lodsb cmp al, 0 jz @f inc cx jmp @b @@: pop si ret |
|||
![]() |
|
sinsi 04 Sep 2011, 06:35
Code: org 100h mov edx,81h movzx ebx,byte[edx-1] mov byte[edx+ebx],'$' mov ah,9 int 21h int 20h |
|||
![]() |
|
typedef 04 Sep 2011, 15:05
@sinsi Try to do it with 16 bit registers.
![]() |
|||
![]() |
|
Goplat 04 Sep 2011, 20:32
It's not a good idea to use ah=9 to print a user-inputted string, even if you $-terminate it, because the string can itself contain a $ and then it'll get truncated.
|
|||
![]() |
|
typedef 04 Sep 2011, 21:14
Goplat wrote: It's not a good idea to use ah=9 to print a user-inputted string, even if you $-terminate it, because the string can itself contain a $ and then it'll get truncated. +1 |
|||
![]() |
|
adroit 05 Sep 2011, 03:05
Get the argument and pass it to DX.
Code: org 100h use16 start: xor bx,bx ; clear high & low bytes mov bl,[80h] ; move the length into BX mov byte[82h+bx+1],'$' ; move '$' right after the argument mov ah,9 ; we want to display string mov dx,82h ; message to display int 21h ; display command-line ; wait for keypress xor ax,ax int 16h exit: int 20h ; return to OS And for Goplat's +1 (thanks typedef): Code: org 100h use16 start: xor bx,bx ; clear high & low bytes mov bl,[80h] ; move the length into BX mov byte[82h+bx],0 ; move 0 this time since we are using BIOS interrupt mov si,82h ; message to display call printString ; wait for keypress xor ax,ax int 16h exit: int 20h ; return to OS printString: .getchar: lodsb or al,al jz .finished mov ah,0Eh int 10h jmp .getchar .finished: ret ; return Where you see this line: mov byte[82h+bx],0 ; move 0 this time since we are using BIOS interrupt, I removed the 1 because it brought up letters that were not on command-line. I don't know why. If someone could explain that part for both of us, please. _________________ meshnix |
|||
![]() |
|
Goplat 05 Sep 2011, 18:30
adroit wrote: Where you see this line: mov byte[82h+bx],0 ; move 0 this time since we are using BIOS interrupt, I removed the 1 because it brought up letters that were not on command-line. I don't know why. If someone could explain that part for both of us, please. Really, if you want to nul-terminate the string, it should be [81h+bx], since the command line starts at 81h. If you write to [82h+bx], then you'll write the 0 byte after the 0Dh terminator character; if you write to [82h+bx+1] then you'll write it after the 0Dh plus whatever the next character happened to be (probably something left over from a previous command line). |
|||
![]() |
|
revolution 05 Sep 2011, 21:04
You don't have to null terminate the string at all. Just use 0xd as your terminating character in the printString subroutine.
|
|||
![]() |
|
adroit 06 Sep 2011, 14:38
Goplat wrote:
revolution wrote:
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.