News:

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

what is the wrong with this.....

Started by ahsan, November 20, 2010, 09:35:38 PM

Previous topic - Next topic

ahsan

.model small
.stack 100h
.data
array db 10,20,30,40
.code
main proc

mov ax,@data
mov ds,ax

mov ax,WORD PTR array    ;I'm expecting that after this ax contains ax=2010 (in little endian.)
                                      ;But unfortunately it constians some garbage or some other value but al=20 and ah=10
                                      ;Can any body tell me that what is that why the whole ax doesn/t conatins the whole 2010 but al ,ah can.
mov ax,4c00h
int 21h
main endp
end main

RuiLoureiro

Quote from: ahsan on November 20, 2010, 09:35:38 PM
.model small
.stack 100h
.data
array db 10,20,30,40
mov ax,WORD PTR array    ;I'm expecting that after this ax contains ax=2010 (in little endian.)
                                      ;But unfortunately it constians some garbage or some other value but al=20 and ah=10
                                      ;Can any body tell me that what is that why the whole ax doesn/t conatins the whole 2010 but al ,ah can.
Why not
array       dw 2010
             dw 4030
             dw ....

mov         ax, word ptr array ?

dedndave

#2
the code you have in the original post should work
how are you examining the results ?
use a debugger like debug or symdeb
step through the instructions with the "T" command
when the next instruction is MOV AX,4C00h, examine the value in AX

MichaelW

There is nothing wrong with the code that I can see. Here is what I get tracing through it in DEBUG:

D:\MASMDOS>debug ahsan.exe
-r
AX=0000  BX=0000  CX=0012  DX=0000  SP=0100  BP=0000  SI=0000  DI=0000
DS=0B7C  ES=0B7C  SS=0B8E  CS=0B8C  IP=0000   NV UP EI PL NZ NA PO NC
0B8C:0000 B88C0B        MOV     AX,0B8C
-t

AX=0B8C  BX=0000  CX=0012  DX=0000  SP=0100  BP=0000  SI=0000  DI=0000
DS=0B7C  ES=0B7C  SS=0B8E  CS=0B8C  IP=0003   NV UP EI PL NZ NA PO NC
0B8C:0003 8ED8          MOV     DS,AX
-t

AX=0B8C  BX=0000  CX=0012  DX=0000  SP=0100  BP=0000  SI=0000  DI=0000
DS=0B8C  ES=0B7C  SS=0B8E  CS=0B8C  IP=0005   NV UP EI PL NZ NA PO NC
0B8C:0005 A10E00        MOV     AX,[000E]                          DS:000E=140A
-t

AX=140A  BX=0000  CX=0012  DX=0000  SP=0100  BP=0000  SI=0000  DI=0000
DS=0B8C  ES=0B7C  SS=0B8E  CS=0B8C  IP=0008   NV UP EI PL NZ NA PO NC
0B8C:0008 B8004C        MOV     AX,4C00
-


eschew obfuscation

dedndave

by the way,
20 decimal = 14h
and
10 decimal = 0Ah
:bg

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

yes - i use that specific post as a reference guide

:P

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

ahsan

but why ax contains some other  value while the ah and al contains the correct value i'am using the MASM 611

clive

Quote from: ahsan on November 21, 2010, 02:16:51 PM
but why ax contains some other  value while the ah and al contains the correct value i'am using the MASM 611

Because the registers are 8-bit (0-255) and 16-bit (0-65535) wide, and not some arbitrary width that holds 0-99 that you seem to want it too.

10 and 20 are TWO distinct numbers, the value in AX = (AH * 256) + AL, or 5130 not some random "other" value
.
2**8 = 256
2**16 = 65536

If you want AX = 2010 then you'll need to combine them AX = (20 * 100) + 10

Finally it's not a MASM thing, it's how the 80x86 works. Computers do not typically handle decimal numbers in base 10.

Perhaps you should review your class notes, or recommended text books, to shed some light on this.
It could be a random act of randomness. Those happen a lot as well.