1. Re: Low Level Mem Question & Return
From: Alan Tu
Re: Low Level Mem Question
>Yes, but how does that relate to the megs of memory I have. Do the
>addresses just start from 1. (I know about conventional, upper, and
>extended mem and their starting/ending positions. These numbers are
>bytes, right?
Actually, they start from 0. And yes, they are bytes. The DosRef
file Irv mentioned will give you a map of the memory, and a better
explanation. Also, the Art Of Assembly textbook gives a good explanation,
it's on the web.
Basically, if you have 16 megabytes of RAM, they are numbered from
#000000 - #FFFFFF (0 to 16,777,215 in decimal). The first megabyte is
#000000 - #0FFFFF (0 to 1,048,576).
That's protected-mode linear addressing, the kind Euphoria uses.
Real-mode uses segments and offsets, so you'll see addresses like
B000:00FF a lot in programming texts. Conversion to protected-mode
addresses is pretty easy. Multiply the segment by 16 (#10) and add
the offset. For example real-mode address B000:00FF,
Hex Decimal
segment B000 2816
x 10 x 16
----- -----
B0000 45056
offset + 00FF + 255
------ -----
B00FF 45311
the protected mode equivalent is #B00FF. You can see why using
hexadecimal is easier. Just remember that 9+1 = A in hexadecimal,
not 10. (common mistake even for pros).
Re: Return Statement Usage
>In general, under what circumstances should one use return at
>the end of a procedure to keep the program from "wandering off"?
Return is really only needed for functions, not procedures.
Every function must return something. Return passes the value
back. The order of execution (keeping the program from "wandering
off") is handled automatically.
You can use return in a procedure if you want to jump out
early, I think... Like using exit to break out of a loop early.
For instance:
procedure Draw_Item( integer item, integer detail )
Draw_Outline( item )
if detail = OUTLINE_ONLY then
return --skip rest of procedure
end if
Paint_Item( item )
if detail = OUTLINE_AND_PAINT then
return --skip rest of procedure
end if
Highlight_Item( item )
Shade_Item( item )
-- no return necessary here, it's automatic
end procedure