Whats wrong with general purpose register

Started by Khurram, October 08, 2006, 06:35:48 PM

Previous topic - Next topic

Khurram

Please help me i am using MSAM611


.model small
.stack 100h
.data
.code
    main proc
     mov  cx,5
    next:
     mov ah,2
   ; mov ah,'B' ;when i use ax upper  register ah to move 'B' it get compiles but display nothing upon execution why?
   ; mov al,'B' ;when i use ax lower  register al to move 'B' it get compiles but display five 'o' upon execution why?
   ; mov bh,'B' ;when i use bx upper  register bh to move 'B' it get compiles but display five 'p' upon execution why?
   ; mov bl,'B' ;when i use bx lower  register bl to move 'B' it get compiles but display five 'q' upon execution why?
   ; mov ch,'B' ;when i use cx upper  register ch to move 'B' it get compiles but display hanging loop 'r' value upon execution why?
   ; mov cl,'B' ;when i use cx lower  register cl to move 'B' it get compiles but display hanging loop 's' value upon execution why?
   ; mov dh,'B' ;when i use dx upper  register dh to move 'B' it get compiles but display five 's' upon execution why?
   ; mov dl,'B' ;when i use dx lower  register dl to move 'B' it get compiles and display me perfectly five 'B' upon execution which should be.
     int 21h
    loop next
    mov ah,4ch  ;service 4ch to move exit
    int 21h
    main endp
end main


I know i dont have right understanding about registers though i have read
from my course book but no where written whats the beahviour of general purpose register correctly please tell me in detail why only dl move correct letter 'B' why not others as well give me nice link for reference.

thanx in advance

Khurram


raymond

Just do a search with your favorite search engine for:

Ralf Brown's Interrupt List

and choose whichever link may be the most suitable for you.

This should explain every detail of the requirements for the content of the various registers when using any of the DOS interrupts.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Khurram

Raymond cant you define about my last posted scenario why it is in your own words??
BTW yours link is not helpful for me this specific scenario.

Please help somebody..

Khurram

sinsi

The only registers DOS needs for this function are AH and DL -


   mov ah,2    ;2 is "Write Character to Standard Output"
   mov dl,'B'  ;the character to write is in DL
   int 21h


You won't get very far without "Ralf Brown's Interrupt List" if you use DOS functions (hint, hint).
Light travels faster than sound, that's why some people seem bright until you hear them.

Khurram

Thanx sinsi

The only registers DOS needs for this function are AH and DL -

You mean to say DOS needs only accumulator register to write Character to Standard Output??

Morever i couldnt understand yet what is "Ralf Brown's Interrupt List"

You won't get very far without "Ralf Brown's Interrupt List" if you use DOS functions (hint, hint).

Please dont mind i am new bie

Khurram


raymond

You could consider the various interrupts as library functions which need parameters. Those parameters must be passed in specific registers. "Ralf Brown's Interrupt List" is like a Help file which indicates which registers have to be filled with what kind of data for each interrupt.

If you don't have such a Help file in one form or another, you will never succeed in being able to write DOS programs.

Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Draakie

Hi Khurram,

If you have a look at the function range Interupt 21 - It's pre-requisites for correct
operation are that certain registers on entry contain the correct values for the sub
function called. It's also worth noting that any calls made to the general range of
Interupt 21 or any interupt for that matter - on return - do not guarentee that
register values remain the same on return. To be paranoid about register preservation
will help you loads in future.

In your'e case on the elimentary level :

Sub-function 2 - Print Character to Screen device :

Requires AH = 2 / DL = 'B' - at the minimum.

The reason u're getting funny things happening when using other registers - is because
the requirements of the Interupt function call is just not beieng met.

The general purpose registers (AX,BX,CX,DX etc.) prior to you're code - contain data
from any previous CPU instructions executed - prior to your'e code beieng called.

[ I suspect you were assuming they were all pre-set to Zero ??  ]
[ NOTE THUS : Assume nothing about the contents of registers on entry to your'e code]

Your'e Code:

Moving 'B' to any other registers have no or undesired effect as the DL register contains
garbage. Changing CL,CH,CX is quite dangerous in your'e example - seeing as you're using a LOOP - which is dependent on CX register for it's Counter.( How many times to loop ). Also given the fact
the INT 21 call might have changed CX.

So a quick re-write

main proc
     mov cx, 5
next:
    push cx
      mov ah,2
      mov dl,'B'
      int 21h
    pop cx
loop next
    mov ah,4ch  ;service 4ch to move exit
    int 21h
    main endp
end main

Does this code make me look bloated ? (wink)

sinsi

Download Ralf's list from http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html
This will tell you the registers that need values for all sorts of INTs, not just INT 21h.
Light travels faster than sound, that's why some people seem bright until you hear them.

Khurram

Thanx draakie for yours response

I got yours point a little bit please correct me you mean to say every particular intrept associate with individual register,i mean int21h is for dl which will cause display garbage with issuing with oter then dl register.


Saasi you have given me the link but from which hyper link i have to read for interrupt list there is lot of href.

Please dont bother i am not trying to be spoon feeded.

Khurram

Shantanu Gadgil

#9
Hello Khurram,
Interrupts have what are called as functions (and also sub-functions).

Function means (usually) some value in some specific register before you actually write the int xyz (xyz to be replaced with some number  :bg :bg) statement.

So for example, to display a string on the command prompt, you would be interested in: (read this aloud)  :toothy :toothy
Interrupt 21h, function 9h
the 9h here is the expected value in the ah register.
ALSO, the dx register is expected to be holding the offset of a '$' terminating string (like so "ABCD$")

so when you would write:
mov ah,9
mov dx, offset mymsg ;mymsg is "ABCD$"
int 21h


it would show the string "ABCD" on the prompt.

So this is how you would read the RB (Ralf Brown) list. Interrupt/Function/[Sub-function]

This should get you on the road to "reading up" the Ralf Brown Interrupt List!!! :bg
Best of luck!!!  :U :U

Regards,
Shantanu
To ret is human, to jmp divine!

Khurram

Thanx for all participating but still not clear :( i am just asking very simple question why with general purpose register (ah,al,bh,bl,ch,cl,dh) not showing me same letter which i am moving in these rgister 'B'.

Only dl register showing me same letter 'B' which i am moving 'B'.

I know i am not paying for that , i am also an active member of ORALCE now i am feeling that how new comers feel pain when they dont clear their problem,though you all trying yours best but its me dump who is not getting what magic behind these register i am feeling like beating myself.

.model small
.stack 100h
.data
.code
    main proc
;     mov  cx,5
;    next:
     mov ah,2
   ; mov ah,'B' ;when i use ax upper  register ah to move 'B' it get compiles but display nothing upon execution why?
   ; mov al,'B' ;when i use ax lower  register al to move 'B' it get compiles but display five 'o' upon execution why?
   ; mov bh,'B' ;when i use bx upper  register bh to move 'B' it get compiles but display five 'p' upon execution why?
   ; mov bl,'B' ;when i use bx lower  register bl to move 'B' it get compiles but display five 'q' upon execution why?
   ; mov ch,'B' ;when i use cx upper  register ch to move 'B' it get compiles but display hanging loop 'r' value upon execution why?
   ; mov cl,'B' ;when i use cx lower  register cl to move 'B' it get compiles but display hanging loop 's' value upon execution why?
     mov dh,'B' ;when i use dx upper  register dh to move 'B' it get compiles but display five 's' upon execution why?
   ; mov dl,'B' ;when i use dx lower  register dl to move 'B' it get compiles and display me perfectly five 'B' upon execution.
     int 21h
   ; loop next
    mov ah,4ch  ;service 4ch to move exit
    int 21h
    main endp
end main


here dh displaying me l but only dl showing me B

I lost now.


Khurram

Shantanu Gadgil

As I said before, int 21h has function (service) numbers which is the value in ah.

So (if I remember my DOS days) int 21h, service (function) 2 (ah=2) would print the character stored in dl

As for your question, "why only dl's output is appearing?", because THATS THE WAY IT IS...(for int 21h, ah=2)

So, just to be clear...
before calling int 21h, if ah was equal to 2, upon calling int 21h, it would print the ASCII value of the character in dl.

Thats as simple as I can make it!!!

If the RB list is too complicated/confusing try getting your hands on the Microsoft's Book by Ray Duncan (less exhaustive)

Hope that helps,
Shantanu
To ret is human, to jmp divine!

Khurram

Its now getting me clear  :clap: you said
int 21h print the character stored in dl
Its ok

Tell me one thing more please what does it mean by

service (function) 2 (ah=2)??

One more question

For what would we do to get output which we sotre in others then dl??

Thanx a lot Shantanu Gadgil now my pain is getting releif :)

Khurram


Khurram

One more question when i write the code

.model small
.stack 100h
.data
.code
    main proc
    mov ah,2
    mov dl,'B'
    int 21h
    mov ah,4ch  ;service 4ch to move exit
    int 21h
    main endp
end main

It gives me output 'B' as you said int 21h will show the contents in register dl,
but when i remarks  mov ah,2 like

.model small
.stack 100h
.data
.code
    main proc
;   mov ah,2
    mov dl,'B'
    int 21h
    mov ah,4ch  ;service 4ch to move exit
    int 21h
    main endp
end main

sometime it shows a pop up window which contains an alert type.

MS-DOS Prompt
The NTVDM CPU has encountered an illegal instruction.
CS:89f8 IP:8c09 OP:0f ff c0 07 ff choose 'Close' to teminate the application.


Why this error cause by remarking the ah,2 i mean what ah,2 is doing.

sometime it doesnt show pop up window instead it gets hang, the moment i run the program it get hangs and dont give any output as well dont let pass control to command prompt.

Thanx shantau  :U

Khurram

Synfire

Khurram,

Think of INT 21h as a function which calls other functions. INT 21h contains a table of functions for interfacing with MS-DOS. It uses the AH register to specify which entry in this table to call. Therefore, setting AH to 2 means you want INT 21h to call the second function in it's collection of functions. The second function happens to be the Print Character to Screen function. Just like the 76'th function (4Ch = 76) is the Exit to DOS function. So, in your application, you specify that you want to call the second function in the INT 21h list by setting AH to 2, then you set DL to the character to be outputed, as specified by Ralf Brown's Interrupt List, and trigger the INT 21h function. This displays a character to the screen. Then you exit by setting AH to 4Ch to specify that you want to use 76th function, Exit to DOS, and again you trigger the INT 21h function. Notice that in the Exit to DOS function you didn't have to specify a value for DL. This is because that function doesn't require a value in DL. Each function uses different registers for different things. This is where the Ralf Brown Interrupt List comes in handy. To make things easier for you, try using a macro like:

DOSCALL MACRO fn:REQ
MOV ah, fn
INT 21h
ENDM


You can then change your source code to look like this:

.MODEL small

DOSCALL MACRO fn:REQ
MOV ah, fn
INT 21h
ENDM

.STACK 100h
.DATA
.CODE
main PROC
mov DL, 'B'
DOSCALL 2
DOSCALL 4Ch
main ENDP
END main


And you other code to this:

.MODEL small

DOSCALL MACRO fn:REQ
MOV ah, fn
INT 21h
ENDM

.STACK 100h
.DATA
.CODE
main PROC
next: push ECX
mov DL, 'B'
DOSCALL 2
pop ECX
loop next
DOSCALL 4Ch
main ENDP
END main


Using Ralf Brown's Interrupt list, you can look up the AH functions and pass them as an argument to the DOSCALL macro, and setup any of the required registers for that function before hand. Take a little while to look over his document, it's been suggested several times in this thread and is an invaluable resource.

Regards,
Bryant Keller