News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

NOOB question

Started by MASM, January 02, 2012, 03:05:57 PM

Previous topic - Next topic

MASM

link16 sounds a good idea (I can't remember using link16 though)

@jj2007: I would like to start where I left with 16 bits and then move on to 32 bits

(I found a junk of code which switches my 80386 from real mode to protected mode AND I would like to implement it)

my currect program is to  show the concept of text mode

store an ascii value into video memory and BANG it appears on the screen


dedndave

well - in the old days, it was just called link
we call it link16 or link563 (it's version 5.63) so that it can co-exist with our 32-bit linker
the newer versions of link do not support 16-bit code

MASM

I see.

I remember having used the /c (no linking) option with ML but not having used link16

I succeeded in producing a .COM file by now.

there is only one more strange thing about it

I included an ORG 0100H instruction to let the code start at 0100H

still my linker says: L4055: start address not equal to 0x100h for /TINY

what now?

dedndave

i am playing with this....
        .MODEL  Tiny
        OPTION  CaseMap:None

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

        .CODE

;------------------------------------------------------------------------------

        ORG     100h

_main   PROC

        mov     ax,0B000h
        mov     es,ax

        mov     al,41h
        mov     es:[0],al

        mov     ah,1
        int     16h
        mov     ah,0
        int     16h

        mov     ax,4C00h
        int     21h

_main   ENDP

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

        END     _main


to create a .COM program....
ml /c MyProg.asm
Link16 /TINY MyProg.obj

however, i am seeing a strange issue
if i build it as an EXE, it works fine - the "A" character is displayed
if i build it as a COM, the "A" character is not displayed   :eek

it may have to do with how NTVDM emulates 16-bit mode - i dunno

dedndave

ok - it is not the COM/EXE thing that makes a difference
i have to create a new console window each time i run it
then - it works as a COM or as an EXE

still - this seems strange - something is amiss   :P

MASM

yes we have the same assembler/ linker setting

Doesn't your linker complain about the starting address not being 0100H for a .COM file ?

Anyway, thanks, I will apopt your code AND then slowly, step by step, migrate to my code.

thus, I will see where I get stuck.

one more thing

your approach to use ES as a pointer looks very elegant

still it is a lot of programming to do to load ES:offset each time for an absolute addressing

isn't there any other way to tell the assembler an absoulte addressing ?

dedndave

well - no matter what method you use, you will have to have a segment register pointing to the video buffer
of course, you can set ES to 0B000h and leave it - it won't be altered for most DOS/BIOS calls

i typically use ES because it is fast to use REP MOVSB, REP MOVSW, REP STOSB, or REP STOSW to fill the screen
also - that frees up the DS register for local data

however, if you want to use some other addressing mode (like the one we are playing with), then using ES is not all that elegant because there is a segment override code byte each time
in such cases, it may be more appropriate to use DS, so that no segment override is required

but - if you want to specify an absolute address, the assembler still expects the syntax...
        mov     ds:[0],al
even though no segment override code byte is required

you can use BX, SI, or DI to address the buffer - no override required

Rockphorr

Quote from: dedndave on January 02, 2012, 05:21:57 PM
no worries - one of the moderators will move it there for you

with 32-bit code, you can directly address 4 gb of space with a single register
with the 16-bit segment:offset, you can indirectly address 1 mb of space


no worries about 16 bit when you write by asm. For 10kb of pure code you work about 2 years.
Strike while the iron is hot - Бей утюгом, пока он горячий

MASM

@DEDNDAVE strange - your code does not produce ANY output in my system

@ROCKPHORR it took me 2 months to produce 4.4 kB of pure code in 6502 machine language

here is something from the 2010 paperback edition:

this book was written on an Archives III microcomputer AND sent from Colombo to New York on one five inch diskette

July 1981

if  300 pages are no more than 360 kB (including formatting) can please anybody tell me why people need GIGABYTES of memory these days?





MASM

I found it!

For some reason my video memory starts at B8000 rather than B0000.

Both your and mine program work now.

Still, for SOME reason I still get a warning from my linker, according to which my segment starts NOT at 100h even though I put an ORG 100h instruction in.

MichaelW

#25
Segment address 0b000h is the base of the display memory for the monochrome alphanumeric modes. For the color alphanumeric modes it should be 0b800h. It was done this way so a monochrome display subsystem  (MDA/HGC) could coexist with the EGA/VGA. This is also the reason that the two systems use different I/O port address ranges.
eschew obfuscation

dedndave

many of the graphics modes start at 0B000h, as well
as they have paged buffers

at any rate - i got an "A" on the screen with a base of 0B000h - i immediately tried 0B800h when the COM didn't work
basically because i wasn't sure which was correct and i was too lazy to look it up   :bg
it's easier to just try it both ways - lol

MichaelW

For the VGA only one of the alphanumeric modes, 7, uses B0000h as the starting host-memory address. The default mode is 3, and I can't recall ever seeing a VGA system that deviated from this, although I have never tested a very recent adapter. Here is the functionality/state information returned by Interrupt 10h, function 1Bh on my P3 system running Windows 2000:

Active video mode            : 3
Character columns            : 80
Bytes per page               : 4096
Current page offset          : 0
Cursor start and end         : 2707h
Current display page         : 0
Base I/O port address        : 3D4h
Character rows               : 25
Bytes per character          : 16
Active display code          : VGA with analog color
Current number of colors     : 16
Current number of pages      : 8
Current number of scan lines : 400
Primary character set        : 0
Secondary character set      : 0
Size of active character set : 256
Character width in pixels    : 9


As to why B000h would work in the default mode, perhaps (some) newer adapters/systems have dropped all support for the monochrome adapters (apart from there having been no systems with ISA slots for > 10 years), and are mapping the display memory into the host address space differently.
eschew obfuscation

MASM

one last question about this issue:

lets say I switch to protected mode and want to do the same thing in protected mode.

my memory model is flat with one data segment ranging from 0 to 800000H

ES is tied to address 0h where the segment starts.

is the following instruction legal?

MOV ES:[68000h],41h

sorry for my question BUT I dont have any manual for my assembler.

dedndave

well - you can get a manual for newer versions, at least - let us know what version of MASM you are using

        MOV     ES:[68000h],41h

the address exceeds 64kb
the largest offset you can use is...
        MOV     ES:[0FFFFh],41h

if you want to address that specific location, you'll have to change the segment register
if you add 6000h to the segment value, it adds 60000h to the calculated physical address
not sure what you are addressing, though   :P

XXXX     segment (16-bit hex)
 XXXX    offset (16-bit hex)
-----    +
XXXXX    address (20-bit hex)