News:

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

register question

Started by xxxx, January 31, 2005, 08:59:43 PM

Previous topic - Next topic

xxxx

first of all,i'd like to say that i'm new to assembly and i am learning by myself by reading books. the only help i could get is online help from forums such as this one.with that said plz forgive me if my questions are stupid.

my question is why can't a 4-bit value be strored in a 16-bit register?couldn't it just be                0000 0000 0000 1111  ?

MichaelW

If you attempt to store a 4-bit value in a 16-bit register:

mov ax,1111b

The instruction will effectively add 12 leading zero bits, so 16 bits will actually be stored, and the value in ax will be 0000 0000 0000 1111b. In general, you can store any bit value that will fit in the register.
eschew obfuscation

xxxx

mov al,0f5h
add al,0bh


the answer is 1 0000 0000
what will happen to the 1 given that al is an 8-bit register?

thanks

thomasantony

Hi,
   I think it goes to the carry flag

Thomas Antony :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

MichaelW

The one will be discarded and the carry flag will be set.

The DOS DEBUG program, which AFAIK is included with all versions of Windows, is very useful for answering questions like this. If you don't know how to use it, there is a tutorial of sorts available here:

http://www.old.masmforum.com/viewtopic.php?t=4051
eschew obfuscation

xxxx

suppose ax has the value of FFFFH.
then we set mov al,DH

does the contents of ax change too?

thanks

MichaelW

Yes, because AL is part of AX. Using DEBUG:

-A
0AED:0100 MOV AX,FFFF
0AED:0103 MOV AL,DH
0AED:0105
-R
AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AED  ES=0AED  SS=0AED  CS=0AED  IP=0100   NV UP EI PL NZ NA PO NC
0AED:0100 B8FFFF        MOV     AX,FFFF
-T

AX=FFFF  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AED  ES=0AED  SS=0AED  CS=0AED  IP=0103   NV UP EI PL NZ NA PO NC
0AED:0103 88F0          MOV     AL,DH
-T

AX=FF00  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AED  ES=0AED  SS=0AED  CS=0AED  IP=0105   NV UP EI PL NZ NA PO NC
0AED:0105 0F            DB      0F
-

And for your previous question:

-A
0AED:0100 MOV AL,F5
0AED:0102 ADD AL,0B
0AED:0104
-R
AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AED  ES=0AED  SS=0AED  CS=0AED  IP=0100   NV UP EI PL NZ NA PO NC <- no carry
0AED:0100 B0F5          MOV     AL,F5
-T

AX=00F5  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AED  ES=0AED  SS=0AED  CS=0AED  IP=0102   NV UP EI PL NZ NA PO NC <- no carry
0AED:0102 040B          ADD     AL,0B
-T

AX=0000  BX=0000  CX=0000  DX=0000  SP=FFEE  BP=0000  SI=0000  DI=0000
DS=0AED  ES=0AED  SS=0AED  CS=0AED  IP=0104   NV UP EI PL ZR AC PE CY <- carry
0AED:0104 750F          JNZ     0115
-


eschew obfuscation

xxxx

does any one have any links to tutorials on arithmetic instructions especially on addition on multiword numbers?