The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: Shayaan_Mustafa on June 08, 2014, 01:48:13 AM

Title: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 08, 2014, 01:48:13 AM
Hello experts,

It is my first post to the forum.

I am very fond of Assembly Language and we have taught in university.
My problem is, I want a book or any document in which I could find information how to write directly to the VRAM using int 21h.

I am using MASM and Windows XP.

Here is the sample program about which I am asking:

.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end


This program will write N directly to the VRAM, as our teacher said. But he never told us where to find more examples of VRAM access with int 21h. He recommended us two books, kip irvine book and the intel mircoprocessors by berry b. bray. But in both books I didn't see any example which my teacher had done in the computer laboratory.

I need your help guys.

Thank you all
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: ROBOSPOOK on June 08, 2014, 02:31:25 AM
Shayaan,
  You might try Ralph Browns Interrupt list.  I don't have the URL for it but you can use google to find it. If you cant find it let me know I will get a URL for you.  Also you can try to find a book called "Undocumented DOS" .. by.. of course Ralph Brown.

Hope this helps

ROBO
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Wannabe on June 08, 2014, 03:12:25 AM
Quote from: Shayaan_Mustafa on June 08, 2014, 01:48:13 AM
Hello experts,

It is my first post to the forum.

I am very fond of Assembly Language and we have taught in university.
My problem is, I want a book or any document in which I could find information how to write directly to the VRAM using int 21h.

I am using MASM and Windows XP.

Here is the sample program about which I am asking:

.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end


This program will write N directly to the VRAM, as our teacher said. But he never told us where to find more examples of VRAM access with int 21h. He recommended us two books, kip irvine book and the intel mircoprocessors by berry b. bray. But in both books I didn't see any example which my teacher had done in the computer laboratory.

I need your help guys.

Thank you all

Take a look here:
http://fleder44.net/312/notes/18Graphics/index.html
Basically ah=4ch,INT 21h is just a dos interrupt which in your case ends your program.
The write to VRAM happen just before that line.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Gunther on June 08, 2014, 03:56:09 AM
Hi Mustafa,

your application must first set the appropriate video mode. The link which Wannabe provided is a good starting point. For more sophisticated examples, check your local library for: Richard Wilton: Programmer's Guide to PC Video Systems. Second Edition. Microsoft Press, 1994. ISBN: 1-55615-641-3. If that book isn't available for you, try that link (http://www.ronthomas.plus.com/) as a substitute. Please check out the topic: Synopsis for free book.

And welcome to the forum.

Gunther
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 08, 2014, 04:50:48 AM
that method also works for graphics modes
in fact, i used to use it for video mode 13h (256x200, 256 color), quite often

you can go beyond that, and use direct access for other graphics modes, as well
however, you must get into flipping memory pages of the graphics adapter

with some knowledge of VGA adapters, you can program unsupported or "X modes"
Michael Abrash was, i believe, the first to publish articles on "X" video modes, in his Black Book

http://twimgs.com/ddj/abrashblackbook/gpbb47.pdf (http://twimgs.com/ddj/abrashblackbook/gpbb47.pdf)
http://twimgs.com/ddj/abrashblackbook/gpbb48.pdf (http://twimgs.com/ddj/abrashblackbook/gpbb48.pdf)
http://twimgs.com/ddj/abrashblackbook/gpbb49.pdf (http://twimgs.com/ddj/abrashblackbook/gpbb49.pdf)

GameDev tutorial

http://web.archive.org/web/20070123192523/http://www.gamedev.net/reference/articles/article356.asp (http://web.archive.org/web/20070123192523/http://www.gamedev.net/reference/articles/article356.asp)
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 08, 2014, 07:17:46 AM
Thank you for replies.

@ROBOSPOOK
I have searched Ralph Brown's interrupt list and seen. But it is not solution for what I am looking. By the way, is this the book are you talking about? http://www.amazon.ca/Undocumented-DOS-Programmers-Functions-Structures/dp/0201570645 (http://www.amazon.ca/Undocumented-DOS-Programmers-Functions-Structures/dp/0201570645)

Wannabe
You have given a very good link. It has basics. We have not been taught with all these basics. Just our teacher wrote a programming on the white board with marker and we type in the computer and compiled it and run it.
But I want more examples of it. Let me start here. I want to learn from here.

Guys, I want to learn this video programming from now and here.

Let's take this example.


.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end


OK so let us start.
I know when access to data segment then we use ds, for example
mov ax, @data
mov ds, ax

but here we used es in the second line of the .code
Why?
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: FORTRANS on June 08, 2014, 07:34:30 AM
Quote from: Shayaan_Mustafa on June 08, 2014, 07:17:46 AM
OK so let us start.
I know when access to data segment then we use ds, for example
mov ax, @data
mov ds, ax

but here we used es in the second line of the .code
Why?

Hi,

   The string instructions like STOSW use the ES segment as
part of the destination (storing a word at the address specified
in ES:DI).  That is hard-wired into the instruction.  Even if you
were using a standard MOV, it is useful to use a ES segment
prefix as that leaves DS to point to your data.

Regards,

Steve N.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 08, 2014, 07:35:41 AM
the video buffer segment generally lies somewhere between 0A000h and 0C000h
it depends on the video card and video mode

for most graphics cards and modes
0B800h is the segment for text modes
0B000h is the segment for graphics modes

so, first, you set the video mode with INT 10h, AH = 0
i think when you start out, you are in mode 3
but, let's say we want mode 7
        mov     al,7
        mov     ah,0
        int     10h

that can be simplified to
        mov     ax,7
        int     10h


because mode 7 is a text mode, the buffer will start at B800:0000
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: MichaelW on June 08, 2014, 08:22:56 AM
I'm assuming that the target here is the default 16-color alphanumeric (text) mode.

As far as I can tell Ron Thomas' book deals with the graphics modes, and not the alphanumeric modes.

An HTML version of Ralf Brown's Interrupt List (RBIL) is available  here (http://ctyme.com/rbrown.htm), and the full version  here (http://www.cs.cmu.edu/~ralf/files.html).

To successfully write directly to the buffer you must understand the layout. From the programmer's point of view the buffer is a linear array of character-attribute pairs, where the first byte of the pair specifies the character code and the second byte the character attribute. The character code bytes are always at even addresses and the attribute bytes at odd addresses. So the layout, starting at offset 0 in the buffer is CACACA...

And you must also understand the layout of the attribute byte, here detailed only for the default configuration:

Bit   Description
7    background intensity
6    background red component
5    background green component
4    background blue component
3    foreground intensity
2    foreground red component
1    foreground green component
0    foreground blue component 


So the layout for each attribute byte is IRGBIRGB.

Dave, under Windows XP you do start out in mode 3, but in my tests I had to do a mode set to get any output.

Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 08, 2014, 08:33:45 AM
@FORTRANS
Sorry sir. I am really sorry but I have to say here English is not my native language. I realize you have talked about something good but didn't get fully what you tried to say me. I will understand your words if you simplify your statement.

@dedndave
Sorry sir you too. I will find and I have many books in which I can study and find many many examples with int 10h to write VRAM. But I want to write directly to the VRAM without BIOS interrupt (int 10h). I didn't find any example without this that's why I searched and find masm32.com/board (http://masm32.com/board)

@MichaelW
Thank you sir. I understand that buffer has character and attribute.
I know about the layout. Kindly, go ahead and teach me step by step.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Gunther on June 08, 2014, 08:48:03 AM
Dave,

Quote from: dedndave on June 08, 2014, 07:35:41 AM
for most graphics cards and modes
0B800h is the segment for text modes
0B000h is the segment for graphics modes

in most cases A000h is the segment address of the VGA graphics buffer.

Gunther
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 08, 2014, 10:53:02 AM
yah, that's correct, Gunther
0B000h is used for the CGA graphics modes
it's also used for mode 13h, as i remember
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 08, 2014, 12:28:09 PM
guess i was wrong   :P

mode 13h -> 0A000h

see attached
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: hutch-- on June 08, 2014, 01:35:26 PM
Long ago there was a trick if your DOS memory was not large enough to perform certain tasks, the one I had in mind was Norton Speedisk on what was then large drives. You ran it only in text mode then set the himem.sys option to use the full VGA video address range from A000h to B7FFh and then you could run Speedisk on larger drives. I remember chasing up all sorts of miniature drivers and the like to maximise DOS real mode memory.  :P
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 08, 2014, 01:48:58 PM
i remember   :lol:

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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 08, 2014, 08:17:46 PM
Where is my discussion??

Please tell me why did we use extra segment to set text mode? Why not data segment? Can we use data segment too?
for example;
mov ax, 0b800h
mov ds, ax

?????????????
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Gunther on June 08, 2014, 08:35:31 PM
Hi Mustafa,

Quote from: Shayaan_Mustafa on June 08, 2014, 08:17:46 PM
Please tell me why did we use extra segment to set text mode? Why not data segment? Can we use data segment too?
for example;
mov ax, 0b800h
mov ds, ax

?????????????

the ds register should point to your data. I would use register es for your screen manipulation (see also reply #6 by Fortrans).

Gunther
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 08, 2014, 09:35:01 PM
Gunther is correct
generally, we use DS to point to source data and ES to point to destination data
however, that isn't a hard and fast rule
you could use DS to point to the video buffer segment
just remember that, when DS points to something other than local data, you cannot access it

also, if you use DI (or EDI), and string instructions like STOSx or MOVSx, you must use ES as the destination segment register
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 09, 2014, 12:47:07 AM
Yes I read Fortrans' reply. I wan to talk on the dedndave's post
Quotejust remember that, when DS points to something other than local data, you cannot access it
Please explain this quote sir.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 09, 2014, 01:05:29 AM
this code accesses the graphics buffer - not the text mode buffer
but - the idea is the same

        .MODEL  Small
        .STACK  4096
        .DOSSEG
        .386
        OPTION  CaseMap:None

;####################################################################################

        .DATA

s$Msg   db 'Press Alt-Enter to Exit Full Screen',13,10,24h

;************************************************************************************

        .DATA?

;####################################################################################

        .CODE

;************************************************************************************

_main   PROC    FAR

        mov     dx,@data
        mov     ds,dx

        mov     ax,13h
        int     10h

        mov     ax,0A000h
        mov     es,ax

        xor     di,di
        mov     cx,64000

loop00: mov     es:[di],cl
        inc     di
        dec     cx
        jnz     loop00

        mov     ah,0
        int     16h

        mov     ax,3
        int     10h

        mov     dx,offset s$Msg
        mov     ah,9
        int     21h

        mov     ax,4C00h
        int     21h

_main   ENDP

;####################################################################################

        END     _main


notice that, at the beginning of the program, DS is set to @data (the data segment where the message string is located)
ES is set to the video buffer segment

i could set DS to the video buffer segment, rather than ES
but, then, i would have to set it back to the local data segment before displaying the text message
INT 21h, function AH=9, requires that DS:DX points to the string
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 09, 2014, 01:10:39 AM
the above code is actually a poor example of segment register management
that's because the ES:[DI] segment override is required, which slows it down
i used ES:[DI] because, in 16-bit code, it is common to use STOSB or MOVSB to set video buffer byte values

STOSB is similar to
    mov     es:[di],al
    inc     di      ;assuming the direction flag is cleared


MOVSB is similar to
    mov     al,ds:[si]
    mov     es:[di],al
    inc     si
    inc     di

except that it does not use AL   :P

STOS and MOVS always use ES as the destination segment
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 09, 2014, 06:04:25 AM
I understand all of this now.

.model small
.stack 32h

.code
mov ax, 0b800h
mov es, ax
mov di, 820
mov al, 'N'
cld
mov ah, 01001001b
stosw
mov ah, 4ch
int 21h
end

Again, di is used to set position right?

And I have few more examples to ask. May I post it here in this thread?
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 09, 2014, 06:44:19 AM
yes - you can calculate the position, based on screen dimensions
for example, let's say you are using 80x25 16-color text mode
each character cell uses 2 bytes, 1 for the character, 1 for the attribute
to calculate the DI value for the character byte

DI = 160*Y + 2*X
or
DI = 2*(80*Y + X)

where X and Y are zero-based values (0-79 and 0-24)
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 09, 2014, 07:00:10 AM
try this program
you can' see some of the characters because foreground color = background color
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 09, 2014, 08:58:51 PM
I tried your program and it is a rainbow  :biggrin:

Here is my another program

.model small
.stack 32h

.data
msg db 'D',14,'i',12,'r',11,'e',10,'c',9,'t',8

.code
mov ax, @data
mov ds, ax
mov si, offset msg
mov ax, 0b800h
mov es, ax
mov di, 1920
mov cx, 18
rep movsw
mov ah, 4ch
int 21h
end


This is another example we did but sir didn't make us understand how all this works.

I want to know this time why did we use "mov si, offset msg"? Because in order programs we had in class we write this "mov dx, offset msg"
I think due to movsw we used "mov si, offset msg". Right?

And in the .data segment see the message format. It is "msg db 'D',14,'i',12,'r',11,'e',10,'c',9,'t',8". I tried "msg db Direct,0dh,0ah" but it didn't work. Why?

And we didn't set attribute in above code any where but still the word Direct is colored on the screen. Why and How?
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 09, 2014, 10:47:50 PM
well - in their example, they interlaced the attribute bytes with the character bytes
that means you can use REP MOVSW, which can be faster than other methods

if you want to simplify the data definition (like "Direct"), then you have to use a slower method of moving the data
you might be able to use a macro to help you interlace attributes with characters
i'm not very good at writing macros, but maybe someone else can help on that one
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 09, 2014, 11:15:24 PM
I know how to write macros. But I am 100% sure it can be done without macros.

I know you can help me.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 09, 2014, 11:32:05 PM
well - of course it can be done
but - let's imagine we had a macro that converted this
   INTERLACE msg, "Direct",14,12,11,10,9,8
into this
msg db 'D',14,'i',12,'r',11,'e',10,'c',9,'t',8

it would just make it easier to write the program
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 10, 2014, 01:43:52 AM
And again I want to know why did we use si for offset msg? Why not ds?

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?
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Wannabe on June 10, 2014, 02:06:46 AM
Quote from: Shayaan_Mustafa on June 09, 2014, 08:58:51 PM

I think due to movsw we used "mov si, offset msg". Right?
That is correct.
Look here:
http://www.electronics.dit.ie/staff/tscarff/8086_instruction_set/8086_instruction_set.html#MOVSW
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Gunther on June 10, 2014, 02:11:26 AM
Quote from: Shayaan_Mustafa on June 10, 2014, 01:43:52 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

       movsw

You can check this with the source which Wannabe provided. Thank you Wannabe.  :t It's very instructive for beginners.

Gunther
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 10, 2014, 03:59:13 AM
Yes, I see Wannabe's link.
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?
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Gunther 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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa 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?
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave 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   :t

i suggest you start with chapter 1

https://courses.engr.illinois.edu/ece390/books/artofasm/artofasm.html (https://courses.engr.illinois.edu/ece390/books/artofasm/artofasm.html)
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave 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
BX = base (address)
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)
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave 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)
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 10, 2014, 08:08:48 PM
Quotethose are some very rudimentary questions
you should probably do a little reading before going too much farther   :t

i suggest you start with chapter 1

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.

Quotethe register names have some meaning, actually

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

AX = accumulator
BX = base (address)
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.

Quotemany 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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Shayaan_Mustafa on June 10, 2014, 08:36:19 PM
This is my program

.model small
.stack 32h

.data
msg Db 'MESSAGE'

.code
mov ax,@data
mov ds,ax
mov SI, offset msg
mov ax,0B800H
mov es,ax
mov DI,1920
mov cx,7
mov ah,14
Again:
        LODSB
        STOSW
loop Again
mov ah,4ch
int 21h
end

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.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave 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
your string is at 3e52:e

the segments are relocatable, and may be different each time you run CodeView
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 11, 2014, 12:04:59 AM
QuoteHere 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   :biggrin:

3)
see answer 2a
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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave 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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: MichaelW on June 11, 2014, 05:01:01 AM
Quote from: Shayaan_Mustafa on June 10, 2014, 08:36:19 PM
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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: BlueMR2 on June 14, 2014, 12:08:33 AM
Quote from: dedndave on June 08, 2014, 01:48:58 PM
i remember   :lol:

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.  :-)
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: Gunther on June 14, 2014, 01:36:21 AM
Quote from: BlueMR2 on June 14, 2014, 12:08:33 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
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 14, 2014, 01:51:33 AM
actually, the 8087 had some features that the modern counterparts don't have
although - they lacked some of the nicer trig functions, etc

BlueMR2....

if you are serious about wanting an 8087-1 (10 MHz)

http://marketplace.vintage-computer.com/auction_details.php?auction_search=1&auction_id=111803&start=30&item_type=buy_out&parent_id=1866&limit=10&order_type=DESC&order_field=a.name (http://marketplace.vintage-computer.com/auction_details.php?auction_search=1&auction_id=111803&start=30&item_type=buy_out&parent_id=1866&limit=10&order_type=DESC&order_field=a.name)

same guy - direct link

http://pcequip.com/index.php?cPath=78_80_83 (http://pcequip.com/index.php?cPath=78_80_83)

if i understand the page correctly, that is $40 US
that's a great price - i wouldn't sell the one i have for less than $250 because the -1 is very rare

i have read about guys using an 8087-2 (8 MHz) at 10 MHz
can't comment on success - lol
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: BlueMR2 on June 17, 2014, 03:15:51 AM
Yeah, best price I found even way back in the day was $250.  Very rare piece...

Currently only looking for free or cost of shipping only.  Wife's been out of work for 15 months now, and prospects don't look promising.  Can't get a job around here if you have any experience.  All they want are fresh out of college kids with no experience.  Not much spare money kicking around for things that aren't truly necessary.
Title: Re: Guidance with 16bit MASM in directly write to video RAM using int 21h
Post by: dedndave on June 17, 2014, 03:29:34 AM
i hear ya
similar situation here in the Phoenix area
they want newbies so they can pay bottom dollar

i figure the best avenue might be to start my own small company
it's "more patriotic" to create even 1 decent-paying job,
than it is to create 100 low-paying jobs, make millions of dollars, and stash it in a dubai account