Alright I am new to assembly but I cannot figure out the simplist thing even though I have looked for hours.

I want to make a very simple program that finds the default drive and prints it.


So that would be 19h and interuppt 21, that gets the current default drive. But how do I get it to print the results? Do I have to save the results to a variable and then print it?


Any help would be appriciated.

Thanks

Whenever programming in assembly you should have at least one very good resource for documentation. Google helps too.

Some common INT 21h documentation.

The documentation indicates that function 19h returns the drive number in AL as an integer. You can print it after converting it to an ASCII character.

; get the drive number in AL (0, 1, 2, ...)
        mov ah, 19h
        int 21h

        ; convert the number to a letter ('A', 'B', 'C', ...)
        add al, 'A'

        ; print the character to standard output
        mov dl, al
        mov ah, 02h
        int 21h

Hope this helps.

Whenever programming in assembly you should have at least one very good resource for documentation. Google helps too.

Some common INT 21h documentation.

The documentation indicates that function 19h returns the drive number in AL as an integer. You can print it after converting it to an ASCII character.

; get the drive number in AL (0, 1, 2, ...)
        mov ah, 19h
        int 21h

        ; convert the number to a letter ('A', 'B', 'C', ...)
        add al, 'A'

        ; print the character to standard output
        mov dl, al
        mov ah, 02h
        int 21h

Hope this helps.

Thank you for the much better link for interupts and such.

I just started trying assembly so sorry for the dumb questions. I tried the code you pasted and I assembled it fine but when I run it nothing happens? Is it converting the number to strictly letter 'A' or is it doing it the the exact corresponding letter?

It works for me (using MASM). Of course, I wrapped it up appropriately in the necessary directives and added code to display a better message and to terminate the program.

.model small
.stack 64

.data
str_current_drive_is db 'The current drive is $'

.code

start:	mov ax, @data
	mov ds, ax

	; print "The current drive is " to standard output
	lea dx, str_current_drive_is
	mov ah, 09h
	int 21h

	; get the drive number in AL (0, 1, 2, ...)
	mov ah, 19h
	int 21h

	; convert the number to a letter ('A', 'B', 'C', ...)
	add al, 'A'

	; print the drive letter to standard output
	mov dl, al
	mov ah, 02h
	int 21h

	; exit 0 (success)
	mov ax, 4C00h
	int 21h

end start

How do you mean, "nothing happens"? You aren't seeing any output? Or the program won't run?

Your last question is answered in the comments with the code.

Hope this helps.

Thank you so much, it works now, looks like I forgot to add the whole data thing and some other stuff.


I'm probably going to get a book on assembly too since the web resources are fairly lacking. :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.