News:

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

intstruction question

Started by xxxx, January 31, 2005, 07:57:45 AM

Previous topic - Next topic

xxxx

mov bx,offset data_in

what does that instruction do?specifically what does offset do?

thomasantony

Hello,
    When you do with offset, you are moving the address of that memory location into the register.

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


Programmer's Directory. Submit for free

xxxx

why can't i do it with 'mov bx,@data_in' or 'mov bx,[data_in}'?

thabks a lot!

thomasantony

Hi,
mov bx,[data_in] gets the  word at the address dats_in into bx. As for @ I think it is used to get the segment. I maybe wrong

Thomas Antony
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

@data is a MASM predefined symbol that expands to the segment address of DGROUP (the segment group to which .data and .stack normally belong for a 16-bit program).

For MASM:

mov bx, data_in         ; bx <- contents of data_in
mov bx, [data_in]       ; bx <- contents of data_in
mov bx, OFFSET data_in  ; bx <- offset address of data_in

eschew obfuscation

xxxx

so ' mov bx,data_in' and 'mov bx,data_in' does the same job?which one uses less cycles?

Relvinian

xxxx,

In the code provided by MichaelW, both instructions, (mov bx, data_in  and mov bx, [data_in]) *are* the same instruction in MASM syntax. This is personal style preference on which one you would like to use.

The third instruction is a move of an address into bx which will execute a little faster but have a different result then the first two instructions.

You need to figure out what you are trying to get into the BX register.  Do you want the contents or the address of data_in?

Relvinian

xxxx

the following code is from a book:
   
    .MODEL SMALL
    .STACK64
    .DATA
COUNT EQU 05
DATA DW 27345,28521,29533,30105,32375
ORG 0010H
SUM DW 2 DUP(?)

.CODE
MAIN PROC FAR

MOV AZ,@DATA
MOV DS,AX
MOVCX,COUNT
MOV SI,OFFSET DATA
MOV AX,00
MOV BX,AX

BACK: ADD AX,[SI]
         ADC BX,0
         INC SI
         INC SI
         DEC CX
         JNZ BACK
         MOV SUM,AX
         MOV SUM+2,BX
         MOV AH,4CH
         INT 21H
MAIN ENDP
         END MAIN






my question is why does sum has to be add by 2(SUM+2,BX)?

thanks

MichaelW

For the same reason that SI is being incremented twice. Each word of DATA and each word of SUM occupy 2 bytes, so the address changes in increments of 2 bytes from one word to the next.

MOV SUM,AX    ; Moves the contents of AX into the first word
              ; at the address specified by SUM.
MOV SUM+2,BX  ; Moves the contents of BX into the second
              ; word at the address specified by SUM.

eschew obfuscation

xxxx

thanks a lot.

would the  result still be the same if   ADD AX,[SI]   is replaced with ADC AX,[SI]? 
                                                   ADC BX,0


TQ.

MichaelW

Not necessarily, it depends on the values of the operands. ADD adds the source operand to the destination operand, and sets the carry flag when the result overflows the destination. ADC adds the values of the carry flag, the source operand, and the destination operand. The ADD AX,[SI] would set or not set the carry flag depending on values of the operands, and the ADC BX,0 would copy the value of the carry flag into BX.
eschew obfuscation