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

dedndave

Quote1)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" ?

that is correct
i think that is called "at&t syntax", where the source operand preceeds the destination operand
the operands are reversed in masm syntax
in masm syntax, it would be
        mov     al,0
        sub     al,i8
        mov     i8,al

Sevag.K

slight correction, the result goes in i8, not al.

dedndave

thanks for catching that, Sevag   :P
here is his original question
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" ?

the result goes into i8

elettronico_79

but if I remove the MOV, that is:

mov( 0, al );

    sub( i8, al );


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


what is the instruction to show a register content in decimal?


i haven't undestuud what mean that phrase, could you help me ?

$8000 inverted becomes $7FFF. After adding one we obtain $8000! Wait, what's going on here? -(-32,768) is -32,768? Of course not. But the value +32,768 cannot be represented with a 16-bit signed number, so we cannot negate the smallest negative value.

Why bother with such a miserable numbering system? Why not use the H.O. bit as a sign flag, storing the positive equivalent of the number in the remaining bits? The answer lies in the hardware. As it turns out, negating values is the only tedious job. With the two's complement system, most other operations are as easy as the binary system. For example, suppose you were to perform the addition 5+(-5). The result is zero. Consider what happens when we add these two values in the two's complement system:

               %  0000_0101

               %  1111_1011

               ------------

               %1_0000_0000


We end up with a carry into the ninth bit and all other bits are zero. As it turns out, if we ignore the carry out of the H.O. bit, adding two signed values always produces the correct result when using the two's complement numbering system. This means we can use the same hardware for signed and unsigned addition and subtraction. This wouldn't be the case with some other numbering systems.


Thanks :D

Sevag.K

Quote from: elettronico_79 on November 11, 2010, 08:25:04 PM
but if I remove the MOV, that is:

mov( 0, al );

    sub( i8, al );


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

i don't know what you mean by al(0).  sub( i8, al ); means subtract the value of i8 from al.


Quote
what is the instruction to show a register content in decimal

signed or unsigned?

if you want to show a register in decimal, you can use one of two methods:

call one of the decimal output routines.  they are all in the stdout namespace:

putu8, putu16, putu32 for unsigned
puti8, puti16, puti32 for singed

or you can use the put macro and type cast
stdout.put( (type uns32 eax) );  // display eax as an unsigned 32 bit decimal.


Quote
i haven't undestuud what mean that phrase, could you help me ?

$8000 inverted becomes $7FFF. After adding one we obtain $8000! Wait, what's going on here? -(-32,768) is -32,768? Of course not. But the value +32,768 cannot be represented with a 16-bit signed number, so we cannot negate the smallest negative value.

Why bother with such a miserable numbering system? Why not use the H.O. bit as a sign flag, storing the positive equivalent of the number in the remaining bits? The answer lies in the hardware. As it turns out, negating values is the only tedious job. With the two's complement system, most other operations are as easy as the binary system. For example, suppose you were to perform the addition 5+(-5). The result is zero. Consider what happens when we add these two values in the two's complement system:

               %  0000_0101

               %  1111_1011

               ------------

               %1_0000_0000


We end up with a carry into the ninth bit and all other bits are zero. As it turns out, if we ignore the carry out of the H.O. bit, adding two signed values always produces the correct result when using the two's complement numbering system. This means we can use the same hardware for signed and unsigned addition and subtraction. This wouldn't be the case with some other numbering systems.


Thanks :D

it's basically explaining why two's compliment numbering system was chosen rather than just flagging the HO bit for signed representation.  the way the hardware works with binary math made it more convenient to go with two's compliment.

elettronico_79

Quote from: Sevag.K on November 11, 2010, 10:54:36 PM
Quote from: elettronico_79 on November 11, 2010, 08:25:04 PM
but if I remove the MOV, that is:

mov( 0, al );

    sub( i8, al );


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

i don't know what you mean by al(0).  sub( i8, al ); means subtract the value of i8 from al.

for al(0) i mean that after MOV the content of al is 0. Does sub(i8, al) put the result in al?

thanks


dedndave

yes
in MASM, we would write it with the operands reverse order
        mov     al,0         ;set AL = 0
        sub     al,i8        ;subtract i8 from the contents of AL

Sevag.K


yes, just remember that for instructions that have a destination operand, the result is stored in the destination operand.


elettronico_79

#38
what is the difference between HLA and MASM assembly?

i'm reading Art of assembly that speak about HLA, but is HLA a real assembly?
where can i learn MASM assembly?


why if i do 5 + (-5) in binary I obtain 100000000 (256d) instead of 0 ? %00000101 +% 11111011 =% 100000000 (256)



in that code, after i do stdout.putb(PosValue) every time i call in screen PosValue it will show a hexadecimal value?
if in processor number are ever in binary, why here used hexadecimal?
static

    PosValue:   int8;
 
begin twosComplement;



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

    stdin.get( PosValue );

    stdout.put( nl, "Value in hexadecimal: $" );

    stdout.putb( PosValue );




thanks!

Sevag.K

Quote from: elettronico_79 on December 12, 2010, 12:50:13 PM
what is the difference between HLA and MASM assembly?

syntax, features.

Quote
i'm reading Art of assembly that speak about HLA, but is HLA a real assembly?

yes.

Quote
where can i learn MASM assembly?

this forum would be a good place to start, check out the general forums and the genesys support forum.

Quote
why if i do 5 + (-5) in binary I obtain 100000000 (256d) instead of 0 ? %00000101 +% 11111011 =% 100000000 (256)

the answers are always in binary, how you display them varies on the display function you use.

Quote
in that code, after i do stdout.putb(PosValue) every time i call in screen PosValue it will show a hexadecimal value?
if in processor number are ever in binary, why here used hexadecimal?
static

    PosValue:   int8;
 
begin twosComplement;



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

    stdin.get( PosValue );

    stdout.put( nl, "Value in hexadecimal: $" );

    stdout.putb( PosValue );


thanks!

putb is instruction to display in "hex byte" not "binary"
there is only an 8bit binary display function in hla, that is putbin8.

eg:
stdout.putbin8( PosValue );

though in the case of your example, the answer will be 0 since adding 5 + -5 = zero + carry.  it will carry over into word size.

if you want to display a whole dword, you can write 4 consecutive butbin8:

stdout.putbin8( (type byte j[3] ) );
stdout.putbin8( (type byte j[2] ) );
stdout.putbin8( (type byte j[1] ) );
stdout.putbin8( (type byte j[0] ) );

a macro would be useful here if you plan on using a lot of this.


namespace stdout;

#macro putbin32( _parm_ );

stdout.putbin8( (type byte _parm_[3] ) );
stdout.putbin8( (type byte _parm_[2] ) );
stdout.putbin8( (type byte _parm_[1] ) );
stdout.putbin8( (type byte _parm_[0] ) );

#endmacro

end stdout;

...

stdout.putbin32( eax );


elettronico_79

if i write a program that show the register for example by stdout.put(eax) and another program (like internet explorer) is using the same register, i will see the thinks that explorer putted into eax?

dedndave

no
each process or thread has it's own set of registers
when the OS switches between tasks (called context switch), the register set and cpu state for that task is restored
if you want to see the registers in a program, you can use a debugger
there are several types of debuggers
a very simple one is called debug, and may be executed from a console command line
it is useful for debugging 16-bit programs

elettronico_79

#42
i saw that in C++ is possible use the assembly, but the HLA is allowed? o we need another assembly?
in HLA exist the If loigic instruction? an assembly language shouldn't have that instruction, right?

thanks   :U

dedndave

depending on which assembler you use, if/then/else constructs are supported
that, and macros are supported under masm
you can use macros to create even more high-level stuff   :P
it's good to know what goes on underneath, though
otherwise, you aren't learning asm   :bg

elettronico_79

if i've understood right, HLA support the highter level instruction like If, else, while, etc... but there is the possibility to use (in HLA) lower level sstuff like zero flag and other, right?

so, if a debugger is written in a  language, there should be some istruction or method to do what a debugger do? what are someone?

if i write a program in c++ and i need to use assembly, is HLA supported by c++ or i need another assembly language?


thanks and sorry if i bother  :(