I saw an example of writting a "Hello World" program but I am jus not understanding one part:
Why can't I just move segment of "message" in "DS" directly?Code:mov ax, seg message
mov ds, ax
Printable View
I saw an example of writting a "Hello World" program but I am jus not understanding one part:
Why can't I just move segment of "message" in "DS" directly?Code:mov ax, seg message
mov ds, ax
Why: Because they didnt design it that way.
Reason: I have no idea why they designed it that way though.
While reding on the AOA page I found this one out:
It lies in the way the instructions are encoded. Here is the way AOA encodes instructions for their hypothetical x86 processors (and I figure it's not too far away from the real way 80x86 cpus use).
The main part is always 1 byte, and used like this:
aaabbccc
aaa is the main instruction code. It defines wether the instruction is a simple 2 argument instruction, or something else.
simple 2 arguments are mov, add, sub etc.
If it is, bb specifies one operand, ccc the other
There are two mov instructions:
mov register, other
mov other, register
register is always encoded into bb, while other is in ccc
bb is two bits, therefore can have only 4 values: 00, 01, 11, 10
Those say which register to move to/from. These are a, b, c and d, with whatever size extension is used. Therefore, one operand must be one of the main registers.
Now, this is of course much more complicated on a real cpu, but I think it is the reason why you must take this route: to save bits in the instructions.
mov ds, seg message is therefore not possible.
BTW, two mov instructions needing each other aren't good according to AOA. Use this syntax:
mov ax, seg String
mov dx, offset String
mov ds, ax
This maybe is better.
Hey CornedBee! Do you know off hand what other processors
use the x86 instruction set? Someone said AMD processors. Is this true?
Being a kind person I am, let me answer for CornedBee,
Yes, bcos AMD x86 CPUs are Intel x86 compatible. or else how it runs Windows.:D :D
All CPUs you can put into a "normal" PC:
Intel 80x86, Pentium 1, 2, 3, 4
AMD K5, K6, Athlon
Cyrix cpus
etc...
Now isn't that nice of you. :)Quote:
Being a kind person I am, let me answer for CornedBee,