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
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
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
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).
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
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
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
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.
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
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
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
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
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
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
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
Thanx Bryant Keller :U nice explanation now i got clear thoroughly about ah register but its written in my course book about AX register.
AX (accumulator) AX is called the accumulator register because it is favored by CPU for arithmetic operations.
Other operations are also slightly more effecient when performed using AX.
As you quoted
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.like ah,2 (for output function) then for calling this function we call INT21h it means int21h uses
AX (ah) register.
But as my book says
"it is favored by CPU for arithmetic operations"
it doenst match yours quote,though yours quote is too concrete and logical which is clearing me a lot logically.
So the next quote of this para which i extracted from my book
"Other operations are also slightly more effecient when performed using AX."
So is that mean of next para which you deliverd me in my heart and brain??
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.like ah,2 (for output function) then for calling this function we call INT21h it means int21h uses
AX (ah) register.
Thanx a lot
Khurram
What your book is talking about is the opcodes themselves. Whereas we are talking about the INT 21h service. When it says that AX is favored by the CPU for arithmetic, it says so because instructions like div use ax explicitly without it being passed as a parameter. That is two different things, the book is right though. What I was talking about was for the DOS services and not the CPU. DOS services use AH for an index like I mentioned above.
Khurram,
There is also an on-line HTML version of Ralf Brown's Interrupt list, here:
http://www.ctyme.com/rbrown.htm
Thanx for all of you guys raymond,sinsi,draakie,shantu gadgil,Bryant Keller and MichealW ,At that time yours i was not getting yours response but now when i read yours response again alls view looks alike to me now i am getting nicley.
Now i have two question please take out some time and gimme answer of these two question
Q-1)I have written a small program which takes one character input and i want
to print this input at console i am pasting the code here and giving my
understanding in front of all commands please read this my undrstanding in
front of line and correct me if i am wrong ,if i am not wrong anywhere then tell
me i am getting nicely.
Q-2)Now other problem is this program take me 1 character input but print it
adjacnet to this input character while i wana print it in next line i mean how
can i pass carriage return to get the output at second not adjacent to input
character.
.model small
.stack 100h
.data
.code
main proc
mov ah,1 ;<------service no 1 for taking one input character
int 21h ;<------Int 21h function calling the function from ah register to take one input character and move this input character into al register
mov ah,2 ;<----service no 2 for printing input character which is in ah
mov dl,al ;<----moving al contents into dl register
int 21h ;<----Int 21h function calling the function from ah register to print output from dl register
mov ah,4ch ;<--service 4ch to move exit from dos shell or ???
int 21h;<----calling 4ch service from ah register
main endp
end main
Thanx all of you guys you alls are my teacher :)
I am waiting for yours response.
Khurram
Q1:
Everything looks OK to me except:
service 4ch to move exit from dos shell or ???
This description is from the Microsoft MS-DOS Programmer's Reference:
"End Program (Function 4Ch) terminates the current program and returns control to its parent program."
The parent program is normally, but not necessarily, command.com.
Q2:
The Display Character function (ah=2), like the other DOS display functions AFAIK, calls the BIOS Write Teletype function (Interrupt 10h, ah=0Eh), so it can correctly handle the carriage return, linefeed, and backspace characters. You will need to send both a carriage return and a linefeed, and you will need to preserve the value in AL around the calls (otherwise the value will be overwritten).
MichaelW would you please paste the code here..
I tried
.model small
.stack 100h
.data
.code
main proc
mov ah,1
int 21h
mov ah,0Eh
mov dl,ah
int 21h
mov ah,2
mov dl,al
int 21h
mov ah,4ch
int 21h
main endp
end main
When i run this program it take me input ad then print a sympol (->) right adjacent to this input
character.
While though i moved the E0h in ah register it should print -> after taking input then print input
character as an output character for which i used ah,2.
I mean it seems me my above code just run after taking input till
mov ah,0Eh
mov dl,ah
int 21h
after that it skips
mov ah,2
mov dl,al
int 21h
and goto
mov ah,4ch
int 21h
Khurram
DOS function 01 is "Read character from standard input, with echo"
mov ah,1
int 21h
DOS function 0eh is "Select default drive" and needs the new drive number in DL - MichaelW was referring to BIOS function 0eh "Write teletype" which is INT 10h, so
this code is wrong and should be discarded
mov ah,0Eh
mov dl,ah
int 21h
DOS function 02 is "Write character to standard output" (usually the screen) and needs the character in DL
mov ah,2
mov dl,al
int 21h
And finally DOS function 4ch is "End program" where you can use AL to return a code to the calling program (e.g. ERRORLEVEL in a .bat file)
mov ah,4ch
int 21h
So to put it all together, try this
mov ah,1 ;read a char from the keyboard
int 21h
push ax ;save the char just read
mov ah,2 ;write a char to the screen
mov dl,0dh ;this is the CR (carriage return) char
int 21h
mov ah,2 ;write a char to the screen
mov dl,0ah ;this is the LF (line feed) char
int 21h
pop ax ;get the char from the keyboard we saved earlier
mov ah,2 ;write a char to the screen
mov dl,al ;this is the char from the keyboard
int 21h
mov ah,4ch
int 21h
The BIOS has its own set of functions, just like DOS, except they are accesed (for video) via INT 10h.
You really need some sort of reference for DOS functions, since there are around 100 of them, all using a mixture of registers to pass information.
Thanx a lot for yours reply sinsi you said
You really need some sort of reference for DOS functions, since there are
around 100 of them, all using a mixture of registers to pass information.
Agreed but i dont have such source would you please give me any elementry
level link even though i will bother to you people cause i m dump :).
One more question to all of you guys
service no 1 for taking one input character and move this input character into
AL register.
mov ah,1
int 21h
The push instruction doesnt change the contents of AX instead,it copies the
contents of AX onto stack my question is from where AX has contents while
above instruction move input character into AL register (Lower
register of AX) so does it mean push AX instruction copies the contents of AX
(either it is AL or AH) onto stack and why cant we push lower or upper
register of AX
push ax
What is stack is it register in assembly Or atack is a data structure which store the data in RAM with LIFO discipline??
Thanx again sinsi
Khurram
Hi Khurram,
All I can say is you are getting _yourself_ tangled in too many things all at once. Its good that you want to learn all the stuff but if you try to do too much, you will (probably) not like the whole experience!!!
Questions like "what is a stack", etc though NOT related ONLY to assembly, are a general DATA-STRUCTURES concept.
How stacks would work (and how you would work with stacks) in assembly, would be found in an ASM reference book.
That out of the way...I would say the following (as already told by sinsi) and (would like to add that you should consider these things a MUST-HAVE :bg :bg while learning).
One can learn _only so much_ from a medium like the internet, but the text-books would definitely help you more.
This reference material would also contain sample source codes, which would HELP you, and not make you feel kinda lost! :bg :bg
(I don't want to get into a "text-books better or online resources better" debate here, just mentioning to Khurram that having a DOS reference in text-book format would be a right thing to have)
So, for DOS, start with some kind of manual like the book by Ray Duncan. When (IF) you feel you need to do more than that, then there is the Ralf-Brown list.
Again, I would like to say...do get some kind of TEXT-BOOK as a reference guide!!!
Cheers and Happy Programming,
Shantanu
OK. Go here (http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html) and download Part A, Part B, Part C and Part D.
Then download RBILVIEW and you will have Ralf Brown's Interrupt List on your computer, with a nice easy viewer.
Or, as MichaelW pointed out, it is available online. (http://www.ctyme.com/rbrown.htm)
As Shantanu said, get a book. I have "PC Interrupts, 2nd edition" which is essential for all kinds of real mode stuff (ISBN 0-201-62485-0).
hi
Guys you are right i need some reference book but in this book there is no
sample code or example , what MichealW gave me link its interrupt list which
tells how to do and what to do but without example which is comlicated for
me cause i am newbie.I have serached in my refernce book about showing the
string at console but only get the interrupt ah,9 for ouput the string.I tried
but no luck i hope you guys will help me.
.model small
.stack 100h
.data
string db 'Khurram:$'
.code
main proc
mov ah,9
mov dx,offset string
int 21h
mov ah,4ch
int 21h
main endp
end main
above code compiles but giving some machine code as an ouput why.
Khurram
If you look in the Interrupt List at the entry for Interrupt 21h Function 09h, you will see that the function expects the string to be at DS:DX. In other words, the string must start at the offset address specified by DX, in the segment specified by DS. The problem here is that DS is not set to your data segment. For an EXE program, the program itself must set DS to the data segment. The easiest method of doing this is to place a .STARTUP directive at the entry point of the program.
.model small
.stack 100h
.data
string db 'Khurram:$'
.code
.startup
main proc
mov ah,9
mov dx,offset string
int 21h
mov ah,4ch
int 21h
main endp
end
Another method is to load the value of the value of the predefined symbol @data into DS.
.model small
.stack 100h
.data
string db 'Khurram:$'
.code
main proc
mov ax, @data
mov ds, ax
mov ah,9
mov dx,offset string
int 21h
mov ah,4ch
int 21h
main endp
end main
Michealw thanx a lot Dear ,i got yours second example but one thing is hitting
me why first we move data segment (@data) into AX register why not
data segment (@data) into DS register.
Is my understanding correct
data segment is [string db 'Khurram:$']??
and this data segment is referred by @data??
Please dear dont irritate just bear me only for some days then i would be picky
by reading manuals.
Khurram
He's moving @data into AX then into DS. You can't directly move @data into DS so you must use a register. This is one of the things the .startup directive does for you. There are certain things you can't move a memory location into, segment registers and other memory locations come to mind. The most common way to achieve this is to move it into a register first 'mov ax, @data' then move the value in the register to the segment register 'mov ds, ax'. You could also probably push/pop the value, but I don't like that method since it's slower.
synfire copuple of confusion please help
-what is @data is it directive which contains data segment memory adress or what is it?
-Is there any reason behind that why we cant move memory location to segment register?
-i have read at several places that first move into AX,then into DS but nowhere written the reason for that we cant move memory register directly to data segment?
-Why only first move into AX there is other register like BX,CX,DX ?
Khurram
If you are a total newbie then I recommend this integrated 16 bit interpreter/debugger/compiler
http://www.btinternet.com/~btketman/tutpage.html
Its an interactive asm tutorial that does most 16bit stuff and will at least let you see what is going on as you write, you can run and change stuff without compiling the code because it's an interpreter.
a. @data is a directive which is used by MASM to represent the .data segment.
b. Because that is how the intel opcodes are designed. Try using this, from Biterider's OA32 package:
m2m macro DstMem:req, SrcMem:req, Reg
ifb <Reg>
push SrcMem
pop DstMem
else
mov Reg, SrcMem
mov DstMem, Reg
endif
endm
that way, you can use 'm2m ds, @data' to preform the push/pop version, or use 'm2m ds, @data, ax'
to use the AX register to move them.
c. Like I said above, there is no opcode for it, so you have to either use the push/pop method or move
through AX method.
d. AX, like you mentioned before, is the prefered opcode. But you can use any of the general purpose
registers such as BX, CX, or DX if you want. It's just customary to use AX.
Regards,
Bryant Keller
Khurram,
If you were to try and move a constant into a segment register, for example with either of these instructions:
mov ds, @data
mov ds, 123
MASM would return "error A2070: invalid instruction operands" because the processor does not have an instruction that can do this. If you were to look in the opcodes.hlp file that is included in the MASM32 package, at the MOV instruction, you would see only two forms of the instruction where a segment register is the destination operand:
mov segreg, reg16
mov segreg, mem16
But when the destination operand is a general-purpose register you would see three forms:
mov reg, reg
mov reg, mem
mov reg, immed
A mov segreg, immed form would be needed to move a constant into a segment register, but the processor does not support this form.
@data is one of the predefined symbols that MASM automatically defines and assigns a value to. When your source code is assembled, at every place in the code that one of these symbols appears, MASM replaces the symbol with its assigned value. The value that MASM would assign to @data would depend on the segment structure of the program, which in turn would depend on the memory model, program layout, version of MASM, etc, but a typical value for a small model might be 05E1h.
For more information see Predefined Symbols here (http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_01.htm).
To see what the .STARTUP and .EXIT directives do, see Staring and Ending Code with .STARTUP and .EXIT here (http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_02.htm)
Thanx a lot Bryant Keller and michael i got yours point i have one more problem
with ah,9 service i know ah,9 service requires that we have the segment of
the text/string in DS and the offset in DX.But when i put remarks for getting
segment of string in DS from one of my code it doesnt works it gives me
garbage as an output,while in other code if i do the same it doesnt give me
any garbage instead it works nicely why?
Code which doesnt work upon puttintg remarks to get segment of string into DS.
.model small
.stack 100h
.data
str1 db 'Khurram$'
str2 db 'Siddiqui$'
.code
main proc
mov ax,@data
; mov ds,ax
mov dx,offset str1
mov ah,9 ;Int 21h, subfunction 09h can be used to print a string on the
;screen. Here,you'll need to put the number 09h in the AH
;register, the segment address of the string in DS and the
;offset address of the string in DX. The string must be
;terminated with a $ sign, so if you want to print you name
;"Khurram!" on the screen, the string should be: Khurram!$.
;This example routine could print such a string on the screen
;for you.
;--
;OR
;For this interrupt it requires that we have the segment of
;the text/string in DS and the offset in DX
int 21h
mov ah,4ch
int 21h
main endp
end main
Code which work upon puttintg remarks to get segment of string into DS.
.model small
.stack 100h
.data
var db 7 dup(0)
.code
main proc
mov ax,@data
; mov ds,ax
mov cx,7
mov si,offset var
lbl:
mov ah,1
int 21h
mov [si],al
inc si
loop lbl
mov byte ptr [si],'$'
mov ah,9
mov dx,offset var
int 21h
mov ah,4ch
int 21h
main endp
end main
Thanx again
Khurram
The second code does not display garbage because it is loading the characters you input into the memory that is being displayed. If you remove the code that is loading the characters into the memory, then the remaining code will display garbage.
When the loader loads your program it sets DS to the segment address of the Program Segment Prefix (PSP). The PSP is a 256-byte block of memory that precedes the program in memory. The OS uses the lower 128 bytes of the PSP to store various values that it uses to manage the program, and the upper 128 bytes to store the program's command line. OFFSET var is returning 0Eh, so if DS is set to the segment address of the PSP then the memory that the input characters are being stored in, and the memory that is being displayed, is at offset 0Eh in the PSP. If you load a limited number of characters into this memory and terminate the characters with a "$", then Interrupt 21h Function 9 can correctly display those characters. If you do not load characters into this memory, and you load DX with 0Eh and call Interrupt 21h Function 9, it displays whatever is in the memory, continuing until it encounters a "$", or under Windows until Windows kills the program, or under real DOS until the system crashes. The first 100 or so bytes will appear as garbage because they are actually binary data that the OS stored in the PSP.
Starting at offset 0Eh in the PSP, the OS stores three DWORD values that it uses when the program exits. When your code uses this area of memory to store characters, it will not cause an immediate problem, but under real DOS it likely would cause a problem when the program exits. As a general rule, your program should avoid writing to memory that it does not own.
Thanx Micahel i got yours point a little bit but will ask you laterz about it more.
I have request to Admin of this forum please dont DELETE this post if its inactive for some days
cause i came around with some other urgent work for that i will be away from this forum
for somedays ,after resume i will use this same thread to ask questions,all guys helped me a lot i
was not able how to proceed but Thanx to all they pushed me in good direction now i am
enjoying assembly :)
will back very soon with some more stupid problems
Thanx all you guys
Khurram
hi allz guys,
I have problems regarding understanding about branch prediction?
I surfed the google and i read about it but still not getting good understanding ,Please share some
thought about it?
Khurram
Khurram,
When a program is being executed by the processor, the processor assumes that certain jump will be taken and others won't. This lets it preload the next instruction after the branch to allow for speedy execution. When the prediction is wrong, then there is a slight stall in execution. The rule here is, conditional jumps which jump backwards are assumed to be taken. Conditional jumps which jump forward are assumed not to be taken. Instead of trying to organize my code to fit branch predictions, I tend to set the predictions myself using the following macros:
; Branch Hint: Taken
BHT MACRO
DB 2Eh
ENDM
; Branch Hint: Not Taken
BHNT MACRO
DB 3Eh
ENDM
This way, if I have a conditional statement which usually jumps forward, I can use 'BHT' as though it's a mneumonic just before the conditional jump to fix prediction therefore removing any stall. I use these macros a lot when doing my WndProc because certain conditional jumps (like the one going to WM_COMMAND) will be executed a lot. Since I like to keep the Messages below my comparsons, I mearly change the line from:
cmp EAX, WM_COMMAND
jz @@wm_command
to:
cmp EAX, WM_COMMAND
BHT
jz @@wm_command
It does add one byte to the code, but it removes the stall so execution is faster. On messages like WM_CREATE, I leave those as normal to avoid using an extra byte, since that jump will only be taken once.
The reason branch hints work the way they do is to optimize for looping. since during loops you generally jump backwards. Another common use for BHT would be done during error checking, believe it or not, most applications I see have a stall when they check for an error because they normally jump forward but don't put any override to inform the processor of this, so the processor assumes the jump will fail and stalls when it doesn't fail.
A good source of information on this is either Anger Fog's site or (the source I use) the "AI-32 Intel Architecture Optimization Reference Manual". The Intel Manuals are available in PDF format from various points on the internet, searching google for the name of the book should return results.
I hope this has helped you.
Regards,
Bryant Keller
Quote from: eek on October 18, 2006, 10:29:41 AM
If you are a total newbie then I recommend this integrated 16 bit interpreter/debugger/compiler
http://www.btinternet.com/~btketman/tutpage.html
Its an interactive asm tutorial that does most 16bit stuff and will at least let you see what is going on as you write, you can run and change stuff without compiling the code because it's an interpreter.
Wow Eek, that's a cool little program! :bg
Quote from: Mark Jones on August 25, 2007, 10:00:33 PM
Quote from: eek on October 18, 2006, 10:29:41 AM
If you are a total newbie then I recommend this integrated 16 bit interpreter/debugger/compiler
http://www.btinternet.com/~btketman/tutpage.html
Its an interactive asm tutorial that does most 16bit stuff and will at least let you see what is going on as you write, you can run and change stuff without compiling the code because it's an interpreter.
Wow Eek, that's a cool little program! :bg
I remember this app :lol
It's reaaaaaaaally old! I even don't remember if it helped me to understand asm better, but it was first I was learning the machine language from...
Its runs on an old HP200LX as well, so you can play with it anywhere.
I'm a bit obsessed with not being trapped in front of a desk, but I want to be able to do widgets on the beach without needing a Pentium3000 triple core laptop.
I've discovered another one recently.
If you get one of these
http://www.pk3.org/Astro/index.htm?pv_software.htm
And download the0402 version
http://pandora.inf.uni-jena.de/p/e/noo/owbasic/basic.html
pop the OWBasic.bin file into the PVs460 unit and you can do Basic programming on an ultra light palmtop with 100+ hours of battery life.