The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 07:11:02 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  Miscellaneous Forums
| |-+  16 bit DOS Programming
| | |-+  what is the wrong with this.....
« previous next »
Pages: [1] Print
Author Topic: what is the wrong with this.....  (Read 7263 times)
ahsan
New Member
*
Posts: 21


what is the wrong with this.....
« on: November 20, 2010, 09:35:38 PM »

.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
Logged
RuiLoureiro
Member
*****
Gender: Male
Posts: 590


Re: what is the wrong with this.....
« Reply #1 on: November 20, 2010, 10:04:32 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 ?
Logged
dedndave
Member
*****
Posts: 12523


Re: what is the wrong with this.....
« Reply #2 on: November 20, 2010, 10:17:24 PM »

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
« Last Edit: November 21, 2010, 01:34:49 AM by dedndave » Logged
MichaelW
Global Moderator
Member
*****
Gender: Male
Posts: 5161


Re: what is the wrong with this.....
« Reply #3 on: November 21, 2010, 12:07:43 AM »

There is nothing wrong with the code that I can see. Here is what I get tracing through it in DEBUG:
Code:
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
-

Logged

eschew obfuscation
dedndave
Member
*****
Posts: 12523


Re: what is the wrong with this.....
« Reply #4 on: November 21, 2010, 01:36:50 AM »

by the way,
20 decimal = 14h
and
10 decimal = 0Ah
BigGrin
Logged
oex
Futurist EDIT: In Training
Member
*****
Gender: Male
Posts: 2008


Everything = Maths * Community2


Re: what is the wrong with this.....
« Reply #5 on: November 21, 2010, 02:04:13 AM »

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

You copied that from my post earlier didnt you Dave lol
http://www.masm32.com/board/index.php?topic=15388.msg125690#msg125690
Logged

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

http://www.hereford.tv
dedndave
Member
*****
Posts: 12523


Re: what is the wrong with this.....
« Reply #6 on: November 21, 2010, 02:14:46 AM »

yes - i use that specific post as a reference guide

Tongue
Logged
oex
Futurist EDIT: In Training
Member
*****
Gender: Male
Posts: 2008


Everything = Maths * Community2


Re: what is the wrong with this.....
« Reply #7 on: November 21, 2010, 02:26:22 AM »

lol
Logged

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

http://www.hereford.tv
ahsan
New Member
*
Posts: 21


Re: what is the wrong with this.....
« Reply #8 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
Logged
clive
Hardcore x86, ARM and MIPS toolsmith
Member
*****
Posts: 1230


Project Looking Glass. Following the white rabbit.


Re: what is the wrong with this.....
« Reply #9 on: November 21, 2010, 04:04:04 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.
Logged

It could be a random act of randomness. Those happen a lot as well.
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!