1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Rep Power

    Number in Array not adding right.

    Using MASM assembler

    I just have one problem what i am supposed to do is implement

    arrayW[0] = arrayB[0] + arrayD[0];
    arrayW[1] = arrayB[1] + arrayD[1];
    arrayW[2] = arrayB[2] + arrayD[2]

    in assembly
    INCLUDE irvine32.inc
    arrayB BYTE 170,193,57
    arrayW WORD 3 DUP(?)
    arrayD DWORD 517,1045,2000
    main PROC
    	call ClrScr
    	call crlf
    	mov ecx, LENGTHOF arrayW 
    	mov edi, DWORD PTR OFFSET arrayD	;addr of first element in arrayD
    	mov esi, DWORD PTR OFFSET arrayB	;addr of first element in arrayB
    	mov edx, DWORD PTR OFFSET arrayW	;addr of first element in arrayW
    	mov eax, 0			; reset accumulator
    	mov ax, [edi]			; mov [edi] to 16-bit 
    	add al, [esi]			; add [esi] to lower half of ax
    	mov [edx], ax			; mov sum to [edx]
    	call crlf
    	call crlf
    	add esi, TYPE arrayB
    	add edi, TYPE arrayD
    	add edx, TYPE arrayW
    	call WriteInt
    	call crlf   
    	loop L1
    	call crlf
    main ENDP
    END main
    Everything is fine until the last number computes itself....the output that i get is 687 1238 1801

    Now I think that i know that 2000 + 57 does not equal 1801

    all of my register should be fitting the values put into them....
    I dont know what the problem is with it....

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Rep Power
    add al, [esi] is an 8-bit add. The carry doesn't ripple into the rest of the AX register so you get:

     07 D0     2000 Decimal 
    +   39       57 Decimal 
     07 09     1801 Decimal
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo