### Author Topic: Guidance with 16bit MASM in directly write to video RAM using int 21h  (Read 17103 times)

#### Gunther

• Member
• Posts: 3585
• Forgive your enemies, but never forget their names
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #30 on: June 10, 2014, 02:11:26 AM »
Because mostly we use these statements;
mov ax, @data
mov ds, ax
mov dx, offset msg

But this time we used si. Can't we use dx again?
No, not with
Code: [Select]
`       movsw`You can check this with the source which Wannabe provided. Thank you Wannabe.  It's very instructive for beginners.

Gunther
Get your facts first, and then you can distort them.

#### Shayaan_Mustafa

• Guest
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #31 on: June 10, 2014, 03:59:13 AM »
Here I have something to ask which I never get to understand. Actually what does this mean DS:[SI] or ES:[DI]? How would you define these two? What are these telling to us?

#### Gunther

• Member
• Posts: 3585
• Forgive your enemies, but never forget their names
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #32 on: June 10, 2014, 05:36:23 AM »
Mustafa,

a DOS real mode address is a logical address: SEGMENT:OFFSET. Both are 16 bit wide. The segment address is in a segment register, which can be CS, SS, DS, ES, FS, GS. You have no access to CS and that is reasonable. You can change SS, but your stack would break down if you do so.
You can access all the other segment registers. The linear or physical RAM real mode address is calculated segment*16 + offset, resulting in a 20-bit address in the range of 00000h to FFFFFh. So DS:[SI] points to one logical address, ES:[DI] points to another and ES:[BX] points to third address. What's the problem? The MOVSW statement is connected with DS:[SI] as pointer to the source and ES:[DI] as pointer to the destination. That's hard wired by Intel engineers and no one can change that. But you should know it.

Gunther
Get your facts first, and then you can distort them.

#### Shayaan_Mustafa

• Guest
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #33 on: June 10, 2014, 06:49:29 AM »
I have attached a picture. See it. I have few questions regarding it.

My programming is mostly related to the 16-bit. So I am focusing on the Table 2-3 as in the figure.

Here are my questions:
1) How do we know when to use SS:[SP] or SS:[BP]? Or we can use both anywhere or their functions are specified separately?
2) How do we know when to use DS:[BX] or DS:[DI] or DS:[SI]? Or we can use them anywhere we want? And What is meant by the sentence "an 8- or 16-bit number"?
3) What is the meaning of this line "ES      DI for string instructions        String destination address"? Is this only for string? Can we not use ES:[DI] for any other purpose?
4) Final. DI is the offset for both ES and DS in the 4th and 3rd lines respectively of the table 2-3. If we use DS:[DI] then we can't use ES:[DI], am I right or wrong?

#### dedndave

• Member
• Posts: 8808
• Still using Abacus 2.0
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #34 on: June 10, 2014, 07:24:33 AM »
those are some very rudimentary questions
you should probably do a little reading before going too much farther

https://courses.engr.illinois.edu/ece390/books/artofasm/artofasm.html

#### dedndave

• Member
• Posts: 8808
• Still using Abacus 2.0
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #35 on: June 10, 2014, 07:32:04 AM »
the register names have some meaning, actually

CS = code segment
DS = data segment
ES = extra segment
SS = stack segment

AX = accumulator
CX = count
DX = data

SI = source index
DI = destination index

SP = stack pointer
BP = base pointer (stack frame base)

there are also Flags register and IP (instruction pointer)

#### dedndave

• Member
• Posts: 8808
• Still using Abacus 2.0
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #36 on: June 10, 2014, 07:35:52 AM »
many of the registers may be used for multiple purposes
however, CS:IP is always used to point to the next instruction to be executed
and SS:SP always points to the current "top of stack" (which is numerically the bottom of the stack)

#### Shayaan_Mustafa

• Guest
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #37 on: June 10, 2014, 08:08:48 PM »
Quote
those are some very rudimentary questions
you should probably do a little reading before going too much farther

https://courses.engr.illinois.edu/ece390/books/artofasm/artofasm.html
I have something to say sir. You will be thinking that I am a blank person in the assembly language. But this is not the case. I know its basics and advance too. I also know how to turn on and off capslock, numlock, etc via assembly language.
Now obviously your question should be then why I ask about basics of the assembly language as in the above quote. Because in talking with expert even about basics, sometimes give rise to those discussions which we don't think and don't found in the book.

Quote
the register names have some meaning, actually

CS = code segment
DS = data segment
ES = extra segment
SS = stack segment

AX = accumulator
CX = count
DX = data

SI = source index
DI = destination index

SP = stack pointer
BP = base pointer (stack frame base)

there are also Flags register and IP (instruction pointer)
I know all these abbreviations sir.

Quote
many of the registers may be used for multiple purposes
however, CS:IP is always used to point to the next instruction to be executed
and SS:SP always points to the current "top of stack" (which is numerically the bottom of the stack)
I know this too :-)

I have some questions related with MASM debugger.
I want to know how to use code view? Because our teacher didn't used it.
Here is the picture of the codeview

#### Shayaan_Mustafa

• Guest
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #38 on: June 10, 2014, 08:36:19 PM »
This is my program
Code: [Select]
`.model small.stack 32h.datamsg Db 'MESSAGE'.codemov ax,@datamov ds,axmov SI, offset msgmov ax,0B800Hmov es,axmov DI,1920mov cx,7mov ah,14Again:        LODSB        STOSWloop Againmov ah,4chint 21hend `I run this program and view it in codeview but where is my message located in the memory? How to see it?
Here is picture of this program in the codeview sir.

#### dedndave

• Member
• Posts: 8808
• Still using Abacus 2.0
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #39 on: June 10, 2014, 10:41:07 PM »
i never got around to using CodeView
i used SymDeb, which is very similar to Debug
so i am not sure about CodeView commands

in SymDeb, you can type ? and press enter to get a list of available commands
the "d" command may be used to dump memory
and, it may be modified to dump bytes, words, dwords, etc
db dump bytes
dw dump words
dd dump dwords
the d command may be further modified with a start address or a range of addresses
d 3E52:0
d 100 200

notice that your code segment is 3E51 and the data segment is 3E52
you can use this command to see the string
db 3e52:0

it will dump bytes, starting at 3e52:0

the segments are relocatable, and may be different each time you run CodeView

#### dedndave

• Member
• Posts: 8808
• Still using Abacus 2.0
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #40 on: June 11, 2014, 12:04:59 AM »
Quote
Here are my questions:
1) How do we know when to use SS:[SP] or SS:[BP]? Or we can use both anywhere or their functions are specified separately?
2) How do we know when to use DS:[BX] or DS:[DI] or DS:[SI]? Or we can use them anywhere we want? And What is meant by the sentence "an 8- or 16-bit number"?
3) What is the meaning of this line "ES      DI for string instructions        String destination address"? Is this only for string? Can we not use ES:[DI] for any other purpose?
4) Final. DI is the offset for both ES and DS in the 4th and 3rd lines respectively of the table 2-3. If we use DS:[DI] then we can't use ES:[DI], am I right or wrong?

1)
SP is the stack pointer
when you PUSH or POP, you can watch it change
sometimes, we add or subtract on the SP register, to reserve space for several and/or larger data items

BP is typically used as a stack frame base pointer
like the SP register, it also references the SS segment
however, the BP register does not change when you PUSH or POP

you will see more use of the EBP register in 32-bit code where function arguments are passed on the stack
in 16-bit code, arguments were often passed in registers
compiled code may have passed arguments on the stack
but, unless you are disassembling compiled code, you rarely saw it used that way
however, BP is still used for local data

there are many forum posts to search on this subject

2a)
for BX, SI, or DI, the default reference segment is DS
however, when using string instructions, ES is the default reference segment for DI
this allows moves and compares across segment boundries

2b)
not really sure why they mentioned 8-bit values - it's a little confusing for learning readers
but, an address offset does not need to be greater than 255

3)
also, you are looking at the default reference segments
you may override them by specifying a different segment
SS:[DI], ES:[DI], even CS:[DI] are allowed
for BP, the default is SS, but may also be overridden to DS:[BP] (or any other segment)

4)
sometimes, DS and ES may have the same value
the question depends on context - that's why i suggested more reading

#### dedndave

• Member
• Posts: 8808
• Still using Abacus 2.0
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #41 on: June 11, 2014, 12:28:28 AM »
i should mention something, so you don't waste a lot of time.....

if your instructor is using 16-bit code, then learn what you must to pass the class
but, 16-bit code is considered obsolete
it won't even run under newer 64-bit OS's
don't spend too much time on it, beyond what's required for class

writing code for 32-bit or 64-bit windows is very different from 16-bit DOS code
in fact, those who have written 16-bit code have a harder time learning it, in some respects
because they have to "un-learn" all the 16-bit segmentation stuff

#### MichaelW

• Global Moderator
• Member
• Posts: 1209
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #42 on: June 11, 2014, 05:01:01 AM »
I run this program and view it in codeview but where is my message located in the memory? How to see it?

If you know where in the data segment it is (for your example code it should be at offset 0), after you load the EXE into CV, trace through the code until you have executed the instructions that initialize DS, then at the prompt (“>”) enter:

d ds:0
Well Microsoft, here’s another nice mess you’ve gotten us into.

#### BlueMR2

• Member
• Posts: 115
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #43 on: June 14, 2014, 12:08:33 AM »
i remember

we used to jump through all sorts of hoops to squeeze the smallest improvement out of the machine
the V20 processor was about 12% faster than an 8086 with the same clock

i had a Juko motherboard that had a 10 MHz V20 (i even bought a 10 MHz 8087)
it boasted 1 Mb of RAM - you could page flip part of it
i also had a 2 Mb LIM memory board
i wrote a specialized device driver that treated the combined extra RAM as a single RAMDRIVE
at boot-time, i copied the most common external DOS commands and my favorite EXE's into the RAMDRIVE

I'm doing more than remembering.  I just dug out my old 8088 machine the other day...  10mhz.  Never was able to find an 8087 for it (will accept one if somebody has one to give away!).  768 KiB of RAM, 640 maps the normal way.  The last 128 can be used as a ramdisk with a special driver (no idea where it maps, I've scanned upper memory ranges and never found a read write window that corresponds to it).  Currently has a 1 MiB 16-bit VGA card stuffed into (actually, hanging over the edge of) an 8-bit slot.  Works fine though.  :-)

#### Gunther

• Member
• Posts: 3585
• Forgive your enemies, but never forget their names
##### Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
« Reply #44 on: June 14, 2014, 01:36:21 AM »
I'm doing more than remembering.  I just dug out my old 8088 machine the other day...  10mhz.  Never was able to find an 8087 for it (will accept one if somebody has one to give away!).  768 KiB of RAM, 640 maps the normal way.  The last 128 can be used as a ramdisk with a special driver (no idea where it maps, I've scanned upper memory ranges and never found a read write window that corresponds to it).  Currently has a 1 MiB 16-bit VGA card stuffed into (actually, hanging over the edge of) an 8-bit slot.  Works fine though.  :-)

So you can do some retro programming.

Gunther
Get your facts first, and then you can distort them.