News:

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

use the registry correctly

Started by elettronico_79, October 08, 2010, 05:35:43 PM

Previous topic - Next topic

elettronico_79

#15
in what sense the processor save the registres first to motify them? where it save them?

if the variables must be initialized by "static" why in that code were used "var" ?

var

    i8:     int8;

    i16:    int16;

    i32:    int32;

thank!

Sevag.K


the processor doesn't save them, the operating system [os] does.  the os maintains its own memory space and allocates process memory as requested.

in hla, when you use a 'var' it means hla is allocating space in the process stack for those variables, so the memory space is allocated dynamically rather than reserved in the initial process memory.

if you use 'static' or 'readonly', the memory space is a part of the object code and loaded into memory by the os.

if you use 'storage', the memory is reserved, so it takes less physical space.  reserved memory is also allocated by the os when the object is loaded into memory.


elettronico_79

so if i use "var" I can change the variable valor dinamically by the program (if i program that to do it) ?

in that line:

stdout.put( "2**(", LoopCntr:2, ") = ", pwrOf2:10, nl );

the "**" mean raised?

why in LoopCntr:2 and in pwrOf2:10 there is the colon ? what mean?

thanks!

Sevag.K

Quote from: elettronico_79 on October 19, 2010, 02:47:07 PM
so if i use "var" I can change the variable valor dinamically by the program (if i program that to do it) ?

well yes, but that's not what it means.  you can do the same with static and storage variables.  what var means is that the memory for the variable is allocated dynamically on the stack.


Quote
in that line:

stdout.put( "2**(", LoopCntr:2, ") = ", pwrOf2:10, nl );

the "**" mean raised?

that part will print out the string "2**(" on the output.

Quote
why in LoopCntr:2 and in pwrOf2:10 there is the colon ? what mean?

thanks!

those are for formatting strings on the output into columns, they serve no other purpose.

elettronico_79

for example LoopCntr:2 will be formatted in 2 columns ?


elettronico_79

if i add the exadecimal value 9 + 1 by an hla program, it give me a decimal or exadecimal value? if exadecimal, how can i have a decimal result ?

what's the difference between     stdout.puti32( ebx );   and     stdout.put( ebx );   ?

thanks!

Sevag.K

Quote from: elettronico_79 on October 31, 2010, 04:49:51 PM
if i add the exadecimal value 9 + 1 by an hla program, it give me a decimal or exadecimal value? if exadecimal, how can i have a decimal result ?

do you mean hexadecimal?  if you want to use hexadecimal, use the hexadecimal notation, eg: $9 + $1


Quote
what's the difference between     stdout.puti32( ebx );   and     stdout.put( ebx );   ?

thanks!

all the puti32 functions convert the output to 32 bit integer before displaying.  if you use the put macro instead and don't specify type, the display for registers will be in expanded hexadecimal format, eg: 32 bit register will display 8 characters.


dedndave

you aren't actually adding hex values
you are adding binary values
CPU's don't speak hexidecimal, strictly speaking - programmers do
hex is a convenient way to express and comprehend binary values

elettronico_79

sorry if i make some mistake with english but isn't my mother tongue.

so if I use puti32 and in eax there is the decimal 23.4, will be converted in 23 ?

what mean "the H.O. bit of a number is a sign bit" ? if I have $7FFF how I can know that it's positive?


i haven't understand what are the instruction NOT, AND, OR, XOR for?

i have found that example program. the first part is simple, but if I write the 2 operands it put the first in ecx (why?) and what do after by AND ?

program LogicalOp;

#include( "stdlib.hhf" );

begin LogicalOp;



    stdout.put( "Input left operand: " );

    stdin.get( eax );

    stdout.put( "Input right operand: " );

    stdin.get( ebx );

                                                           

    mov( eax, ecx );

    and( ebx, ecx );

    stdout.put( "$", eax, " AND $", ebx, " = $", ecx, nl );

    end LogicalOp;


thank!

Sevag.K

Quote from: elettronico_79 on November 01, 2010, 05:41:02 PM
sorry if i make some mistake with english but isn't my mother tongue.

so if I use puti32 and in eax there is the decimal 23.4, will be converted in 23 ?

no, it will display the contents of EAX as a 32 bit integer.  if you want to display a 32 bit real value, use putr32 function.  read the manual on how to change decimal to scientific notation if desired.


Quote
what mean "the H.O. bit of a number is a sign bit" ? if I have $7FFF how I can know that it's positive?

the H.O. bit or 'high order bit' is the bit to the left-most bit of the register.  that is the sign bit for signed evaluation.  if it is a 1, the number is negative, if 0, the number is positive.


Quote
i haven't understand what are the instruction NOT, AND, OR, XOR for?

i have found that example program. the first part is simple, but if I write the 2 operands it put the first in ecx (why?) and what do after by AND ?

program LogicalOp;

#include( "stdlib.hhf" );

begin LogicalOp;



    stdout.put( "Input left operand: " );

    stdin.get( eax );

    stdout.put( "Input right operand: " );

    stdin.get( ebx );

                                                           

    mov( eax, ecx );

    and( ebx, ecx );

    stdout.put( "$", eax, " AND $", ebx, " = $", ecx, nl );

    end LogicalOp;


thank!

these are logical operations that change the destination operand.  we put it in ecx first to preserve what is in eax.

to learn more, read this quick description

http://www.ralphb.net/IPSubnet/logical.html

then read this more in depth review

http://en.wikipedia.org/wiki/Bitwise_operation

to experiment, i have written a program that allows you to see things in action.

see ccalc.zip attached.  the ccalc.txt manual has some demo logical calculations you can test out on cCalc and see how they affect the registers.




article on

elettronico_79

#26
to have the H.O. bit i should convert the number in binary system? for example is $7FFF positive because in %0111_1111_1111_1111 the more left digit is 0 ?

dedndave

Quotefor example is $7FFF positive because in %0111_1111_1111_1111 the more left digit is 0 ?

yes

you must understand that values may be either signed or unsigned
it depends on the context in which they are used
for example, let's take the dword value 80000000h:
if we display it with a decimal routine intended for unsigned integers, it will yield 2147483648
if we take the same value and display it with a decimal routine intended for signed integers, it will yield -2147483648

in calculations, you must know the context
this type of representation is known as "two's compliment"
adding 2 values together yields the same binary result whether they are signed or unsigned
if we add 7FFFFFFFh + 1, it will always yield 80000000h
in a signed context that is an overflow because the range of values (-2147483648 to +2147483647) has been exceeded
in an unsigned context, the range is 0 to 4294967295

now, let's add FFFFFFFFh + 1
again, the binary result will always be the same - 0
however, it is an overflow in unsigned context, rather than signed
that is because the value FFFFFFFFh is -1 on the signed number line
on the unsigned number line, it is 4294967295

elettronico_79

1)that code

    mov( 0, al ); 

    sub( i8, al );

    mov( al, i8 );

mean "sub the value of i8 from al(0) and put the result in al" ?

2)what is the HLA instruction to add two binary or hexadecimals numerrs like %1000 + %1100 or $F + $F ?

3)stdout.putb(); convert the decimal number in an hexadecimal one and show it?

4)in the register the number are in hexadecimal and in the variables in decimal? according to that code:

program twosComplement;

#include( "stdlib.hhf" );



static

    PosValue:   int8;

    NegValue:   int8;



begin twosComplement;



    stdout.put( "Enter an integer between 0 and 127: " );

    stdin.get( PosValue );

    mov( PosValue, al );

    neg( al );

    mov( al, NegValue );

    stdout.put( "Hex result = $", al, nl );

    stdout.put( "Decimal result = ", NegValue, nl );



end twosComplement;



thanks

Sevag.K

Quote from: elettronico_79 on November 04, 2010, 07:39:07 PM
what is the HLA instruction to add two binary or hexadecimals numerrs like %1000 + %1100 or $F + $F ?

do you mean the compile time hla instruction or run time assembly instruction?

at compile time, it's done like the way you have it above.

if you want to add during run time, you have to use the assembly instruction add.

eg:

mov( $F, EAX );
add( $F, EAX );  // EAX = $F + $F


Quote
stdout.putb(); convert the decimal number in an hexadecimal one and show it?

no, it converts the *contents* of the byte sized variable or register to a hexadecimal value for display purposes.  the contents of every variable and register are always binary.  how it is treated is determined by the context of how it was declared or how it's type casted.

Quote
in the register the number are in hexadecimal and in the variables in decimal? according to that code:

the contents are always binary.  the contents can be interpreted in any way you want.

for example, let's assume the register EAX contains the following value:

10111111_10011001_10011001_10011010

this is of course binary.

in hexadecimal, this is shown as: BF99999A
in unsigned decimal, this is as: 3214514586
in signed decimal, this is as: -1080452710
in 32bit real value, this is as: -1.2
in 32 bit real exponential, this is as: -1.2e+00

as you can see, the value changes depending on how you want the context represented.