just my asm example getting current drive/folder

Started by BytePtr, June 05, 2005, 12:35:22 AM

Previous topic - Next topic

BytePtr

Im not prof. in asm but im learning fast. As u know best way to learn is to CODE IT. I was reading "the good old"  Tech Help and i decided put some functions from this to work and i coded it today. Program outputs current folder with drive letter and with light green color (this color can be changed of course). Maybe somebody learns something from it. there is no code optimizations. im sure that and this can be made in better way but its just example.
; (c) 04.06.2005 HuMaX
; Outputs current drive and folder with nice color


.model small
.stack 200h ; 512Kb stack
.data
ketas db 1 dup (?) ; buffer for drive number
kaust db 64 dup (' ') ; buffer for current folder name
videoseg equ 0B800h ; videosegment
pikkus equ $-kaust ; length of current folder name
.code ; code segment starts
.startup ; main program starts
push ax bx cx dx es di si ; save some registers

mov ah, 01h ;---\
mov ch, 20h ;----| HIDE BLINKING TEXT MODE CURSOR
int 10h ;---/

mov ah, 19h ; get current drive
int 21h ; dos interrupt
add al, 41h ; convert to letter, (0 = A, 1 = B, 2 = C, etc.)
mov ketas, al ; ketas = current drive

mov ax, videoseg ; AX = videosegment 0B800h
mov es, ax ; point ES to videosegment

mov ah, 10 ; color = lightgreen
mov cx, pikkus ; cx = length of c. folder name
mov di, offset kaust ; di = offset of folder name
xor di, di ; clear di
wrchar: ; loop begin
lodsb ; load next string byte to AX
mov es:[di],al ; output char to videomem
inc di ; move to next column
mov es:[di],ah ; output color to videomem
inc di
loop wrchar ; loop until all chars all printed

mov ah, 02h ; print char
mov dl, ketas ; ketas = current drive
int 21h

mov ah, 02h
mov dl, ':' ; print colon
int 21h

mov ah, 02h
mov dl, '\' ; print "\"
int 21h ; and result all of this is ":\" without quotes


mov ah, 47h ; get current folder
lea si, kaust ; load effective adress for current folder name
xor dl, dl ; drive C:\
int 21h
cmploop:
cmp byte ptr[si],0 ; end of string?
je aitab ; yes, goto end

mov al,[si] ; nop, mov contents of si to al (char)
mov dl, al ; dl = one char
call prchar ; print this char
inc si ; increment
jmp cmploop ; and do this all again until EOL (end of line)

prchar proc near
mov ah, 02h ; print char
int 21h
ret
prchar endp
aitab:
xor ah, ah ; wait for keypress
int 16h

pop si di es dx cx bx ax ; restore saved registers

.exit ; give control back to DOS
end ; end of program

hutch--

HuMaX,

I moved this posting so it would survive, the Play Pen is a very temporary messing around area and it gets deleted on an iregular basis if one of the moderators thinks it has filled up with too much junk.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

pbrennick

HuMax,
Sorry, but you must feel like a yo-yo.  This is where this code belongs as it is a 16 bit DOS program.

Paul

hutch--

Thanks Paul,

I did not take a close look at the code when I moved it the first time.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php