flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Can't load string dirctly to register dx?

Author
Thread Post new topic Reply to topic
Adcock



Joined: 09 Aug 2017
Posts: 4
Code:
org 256
mov ah,9
mov dx,wtf
int 21h
int 20h
label wtf
db 'Hello World$'     

This works but
Code:
org 256
mov ah,9
mov dx, 'Hello World$' 
int 21h
int 20h
    

This doesn't.
Why?
I am totally new. [To any kind of programming]
Smile

_________________
ReactOS
Open Your Windows To Freedom
Post 06 Oct 2018, 06:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
The DX register is 16-bits wide, 2 bytes. You are trying to load 12 bytes into the 2 byte register. fasm complains because it won't fit.
Code:
mov dx,'a' ;okay DX=0x0061
mov dx,'ab' ;okay DX=0x6261
mov dx,'abc' ;error 0x636261 is too large for the DX register    


Last edited by revolution on 06 Oct 2018, 12:19; edited 1 time in total
Post 06 Oct 2018, 06:37
View user's profile Send private message Visit poster's website Reply with quote
Adcock



Joined: 09 Aug 2017
Posts: 4
Okay. Thanks. Very Happy

Opps...
So I was passing variable's address not content.
Wait.
Isn't dx supposed to work with whatever passed to it?
How does it distinguish between content and address.
Are all addresses 2 bytes long?

Btw, thanks for properly naming this thread. [whoever did it]

_________________
ReactOS
Open Your Windows To Freedom
Post 06 Oct 2018, 08:35
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6968
Location: Kraków, Poland
Adcock wrote:
Isn't dx supposed to work with whatever passed to it?
How does it distinguish between content and address.
An address is just a number, and number is just a sequence of bits. DX contains 16 bits and how the bits are interpreted is up to you, you can use various instructions to process these bits depending on how you want to view them. These 16 bits can be interpreted as address, as an unsigned number, as a signed number, as a Unicode character code (which is also just a number), etc.

For example, if you put a number 102 into DX, it is a binary number 1100110b and these are the bits that are set in DX. Depending on how you then use this value, it may be interpreted in different ways, for example this number corresponds to ASCII/Unicode character "f", so if you use this value where it is interpreted as character, it is going to be seen as such. If you use this value as an address, this is going to be an address of something stored starting from 102th byte of memory (counted starting from 0 within a segment or linear address space, but that is another story).

Adcock wrote:
Are all addresses 2 bytes long?
They are when you use a 16-bit processor, or a 16-bit compatibility mode of a modern CPU. The bitness of a processor usually reflects exactly that - how large the addresses are. A 32-bit CPU uses addresses that are 4 bytes long and 64-bit CPU uses addresses 8 bytes long.
Post 06 Oct 2018, 10:01
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 424
Location: Belarus
Tomasz Grysztar wrote:
Adcock wrote:
Are all addresses 2 bytes long?
They are when you use a 16-bit processor, or a 16-bit compatibility mode of a modern CPU. The bitness of a processor usually reflects exactly that - how large the addresses are. A 32-bit CPU uses addresses that are 4 bytes long and 64-bit CPU uses addresses 8 bytes long.

Well, to be precise, in 16-bit real mode the full address is 32 bits, while 16 bits is the size of an offset, i.e. the most used part of such address. Just for the sake of completeness…
Post 06 Oct 2018, 12:00
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6968
Location: Kraków, Poland
DimonSoft wrote:
Tomasz Grysztar wrote:
Adcock wrote:
Are all addresses 2 bytes long?
They are when you use a 16-bit processor, or a 16-bit compatibility mode of a modern CPU. The bitness of a processor usually reflects exactly that - how large the addresses are. A 32-bit CPU uses addresses that are 4 bytes long and 64-bit CPU uses addresses 8 bytes long.

Well, to be precise, in 16-bit real mode the full address is 32 bits, while 16 bits is the size of an offset, i.e. the most used part of such address. Just for the sake of completeness…
Well, the actual linear addresses used by real mode are 20-bit (plus HMA as a quirk of the segment*16+offset addressing scheme). But I think this was not the right moment to introduce these concepts. I think .COM program is an excellent learning environment that resembles a 16-bit equivalent of flat memory model.
Post 06 Oct 2018, 12:06
View user's profile Send private message Visit poster's website Reply with quote
Adcock



Joined: 09 Aug 2017
Posts: 4
Okay.
Thanks guys.
Very Happy

_________________
ReactOS
Open Your Windows To Freedom
Post 06 Oct 2018, 12:16
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 424
Location: Belarus
Tomasz Grysztar wrote:
DimonSoft wrote:
Tomasz Grysztar wrote:
Adcock wrote:
Are all addresses 2 bytes long?
They are when you use a 16-bit processor, or a 16-bit compatibility mode of a modern CPU. The bitness of a processor usually reflects exactly that - how large the addresses are. A 32-bit CPU uses addresses that are 4 bytes long and 64-bit CPU uses addresses 8 bytes long.

Well, to be precise, in 16-bit real mode the full address is 32 bits, while 16 bits is the size of an offset, i.e. the most used part of such address. Just for the sake of completeness…
Well, the actual linear addresses used by real mode are 20-bit (plus HMA as a quirk of the segment*16+offset addressing scheme). But I think this was not the right moment to introduce these concepts. I think .COM program is an excellent learning environment that resembles a 16-bit equivalent of flat memory model.

My bad. That’s what happens when I write posts too fast focusing just on the logical concepts. But I like the way this stuff just gets our attention, layer-by-layer.
Post 07 Oct 2018, 09:49
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16057
Location: 112 Ocean Avenue, Amityville
DimonSoft wrote:
Tomasz Grysztar wrote:
DimonSoft wrote:
Tomasz Grysztar wrote:
Adcock wrote:
Are all addresses 2 bytes long?
They are when you use a 16-bit processor, or a 16-bit compatibility mode of a modern CPU. The bitness of a processor usually reflects exactly that - how large the addresses are. A 32-bit CPU uses addresses that are 4 bytes long and 64-bit CPU uses addresses 8 bytes long.

Well, to be precise, in 16-bit real mode the full address is 32 bits, while 16 bits is the size of an offset, i.e. the most used part of such address. Just for the sake of completeness…
Well, the actual linear addresses used by real mode are 20-bit (plus HMA as a quirk of the segment*16+offset addressing scheme). But I think this was not the right moment to introduce these concepts. I think .COM program is an excellent learning environment that resembles a 16-bit equivalent of flat memory model.

My bad. That’s what happens when I write posts too fast focusing just on the logical concepts. But I like the way this stuff just gets our attention, layer-by-layer.
Hehe, well to be even more detailed, the physical (i.e. the hardware) address size is implementation dependant. Original 8086's had a 20-bit address address bus, and any wrap around from seg*16+off was truncated. Later CPUs like the 80286 had a 24-bit address bus and thus had the HMA area available to 16-bit code. The 80386: 32-bit bus. Latest AMD and Intel offerings with 64-bit internals: it is around 52-bits wide, with variations in size depending upon the actual CPU you have. Still no 64-bit address bus that that I am aware of. It would be kinda wasted given the current state of RAM offerings.

Whew, that should be enough to make you go crazy with useless knowledge.
Post 07 Oct 2018, 10:01
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.