Post by Rune KristiansenHi,
I am trying to learn assembly. I am now reading up on segments and how
they work with storing data and jumping to codes etc. I have had
problems with reading data from floppy and then reading the memory
buffer by using DS. It didnt seem to point correctly.
Reading a disk using Int 13h, function 2, ES:BX is expected to point
to the memory area you want the data to go, so... if DS and ES contain
different values, you could--but not neccessarily--have a problem (depending
on what the offset register contained).
Post by Rune KristiansenThen i noticed a thing called segment override where I can write
mov si, ds:[0000h]
With "general" data transfers, the DS register is implied, and doesn't
need to be specified. Here, a better example of an override would've
been:
mov si, es:[0000] , or,
mov si, ss:[0000], or,
mov si, cs:[0000], or...
Also, remember that when using "indirect" addressing, via register, that
certain registers imply that a specific segment register will be used...
unless you use a segment override. For example:
mov ax,[bx], means that the 16 bit value at DS:[BX] will be copied
into the AX register. Whereas:
mov ax,[bp+02], will get the value at SS:[BP+02]
stosb will copy the value in AL to ES:DI
movsb copies the 8 bit value at DS:SI to ES:DI.
With the "string" instructions, you can, if need be, override the
source segment, such as:
lods byte ptr cs:[si], but not so with the destination.
Post by Rune KristiansenWhat i at least think this is doing is putting my offset address into
SI so that by reading si like, mov ax, [si], i will get the value
located at ds:si (or 2000h:000h.. or similar)...
Correct.
Post by Rune Kristianseni am really not sure,
but actually its not the point either.
You mean I just wasted all that time? ;)
Post by Rune KristiansenThe point is that nasmw doesnt support segment override. Am i correct?
I don't know a thing about nasm. I assume the "w" means Windows?
All bets are pretty much off, then. For one thing, segment registers
mean something else entirely in 32 bit protected mode.
Post by Rune KristiansenWould using masm be a better choice?
Ok... either you're using the wrong assembler for what you're trying
to accomplish/learn, or you're going about <whatever it is you're
wanting to do> the wrong way for the OS you're writing for.
If you're writing for DOS, then... yeah, either masm or (I'm assuming)
nasm. If you're writing for Windows, then you wouldn't, generally speaking,
concern yourself with segment registers or interrupts (I know you didn't
specifically mention "interrupts", but... given your first paragraph, I'm
making an assumption).
Post by Rune KristiansenI am using nasmw (0.98.38 win).
win... Well, hopefully someone who knows nasm(w) will jump in, but...
it sounds like yet another case of attempting to start somewhere *other*
than the beginning... or something.
Find some good _basic_ examples (source code, that is). Study them.
When you understand everything therein, move on to some intermediate
examples... and etc. When studying sources, have reference material
to... well, refer to. When you encounter something that isn't "clicking",
it would help, *tremendously*, to ask _specific_ questions, provide
_specific_ examples (such as the section of source code itself, whether
yours or the one you're studying).
I hope that doesn't come off as too harsh, or anything, but the phrase,
"trying to learn assembly", followed with--practically in the same breath--
problems related to disk I/O and buffer access with segmented addressing...
To me (and maybe it's *just* me, I dunno), implies a bit of a gap, and of
course there's the question of OS...
Since your interest appears to be Windows, I, for one, cannot recommend
highly *enough*, the following two sites:
http://www.masmforum.com/index.php
http://win32asmboard.cjb.net/
Look for MASM32, which is a complete package, and includes *invaluable*
references, examples, and tutorials.
For the more basic stuff... (addressing modes, for example)... to be honest,
I really don't know where to direct people. I got started long before there
was such a thing as "a web site", and... I just don't know what's out
there, for the beginner (nor do I know what you already have to work
with/learn from). there is, of course, Randy Hyde's very highly regarded
Art of Assembly, which you can find here:
http://webster.cs.ucr.edu
I've never read it though (hence, usually forget to even mention it), and
my background is with MASM, exclusively (a distinction which would
make sense, once you're familiar with Randy's work).
Well anyway... Do some downloading, dive in, and between here and
the boards, you'll find all the help you need.
Very good luck to you! :)
Jeff
http://www.jefftturner.com (may be temporarily unavailable)