Search code examples
assemblymasmirvine32

assembly error initializer magnitude too large for specified size


I fixed the error, but now can someone suggest a way to make CountNearMatches count how many near matches are in the two arrays. I am using the diff variable as the maximum allowed difference.

This is what i have so far:

    INCLUDE Irvine32.inc

CountNearMatches PROTO,           ; procedure prototype
    arr1:PTR SDWORD,
    arr2:PTR SDWORD,
    diff3:DWORD

.data

arraySyze DWORD 6
    diff DWORD 3
    index DWORD  0           ;var to use as the first index

    Array1  SDWORD  15, 9, 11, 13, 19, 6
    Array2  SDWORD  14, 5, 3, 12, 1, 4  

    text1 BYTE "************* ASM *****************", 0
    text2 BYTE "*** Counting Nearly Matching Elements ***", 0
    text3 BYTE "the arrays are:...", 0
    text4 BYTE "Nearly Mathces were: ",0

.code
main PROC

    mov edx, offset text1       ;hands the address of the firs char of text1
    call WriteString            ;prints out text1
    call Crlf
    call Crlf

    mov edx, offset text2       ; hands the address of the firs char of text2
    call WriteString            ; prints out text2
    call Crlf
    call Crlf

    mov edx, offset text3       ;hands the address of the firs char of text3
    call WriteString            ;prints out text3
    call Crlf

    mov  esi,OFFSET Array1      ; puts the offset of array in esi
    mov  ecx,arraySyze          ;6
    mov  ebx,TYPE Array1                            
    call DumpMem
    call Crlf

    mov  esi,OFFSET Array2      ; puts the offset of array in esi
    mov  ecx,arraySyze          ;  6
    mov  ebx,TYPE Array1                            
    call DumpMem

    mov eax,0
swapLoop:
    mov ebx, index              ;moves index1 to ebx


    ;here i use the registers to add 8 in to the stack addresses
    INVOKE CountNearMatches, ADDR[Array1 + ebx], ADDR[Array2 + ebx], diff

    add ebx, 4                  ;adding 4 to ebx
    mov index, ebx              ;putting ebx back in to index1

    loop swapLoop

    call Crlf

    mov edx, offset text4       ;hands the address of the firs char of text4
    call WriteString            ;prints out text4



    call WriteInt

    call Crlf
    call Crlf


    call WaitMsg                ; Press any key to contineu...
    exit
main ENDP

; ***************************************
; This is where the magic happnes!
; This function gets its parameters from
; the stack and counts the near mathches
; from the two arrays...
; ***************************************
CountNearMatches PROC USES ebx edx esi edi,
    arr1:PTR SDWORD,                    ;points to the first array
    arr2:PTR SDWORD,                    ;points to the second array
    diff3:DWORD                         ;gets the diff from the stack

;------------------------------------------------------- 

    mov eax,[arr1]
    mov ebx,[arr2]
    mov edx, diff3

    sub eax,ebx
    ret
CountNearMatches ENDP

END main

Solution

  • I figured it out.. Now it actually counts all the near matches, not sure if this is the best way but it works. here is what i came up with

        INCLUDE Irvine32.inc
    
    CountNearMatches PROTO,                                  ; procedure prototype
            arr1:PTR SDWORD,
            arr2:PTR SDWORD,
            diff3:DWORD,
            aSize:DWORD
    
    .data
    
            arraySize DWORD 6
            diff DWORD 3
            index DWORD  0                                                          ;var to use as the first index
           count DWORD 0
            Array1  SDWORD  15, 9, 11, 13, 19, 6
            Array2  SDWORD  14, 5, 3, 12, 1, 4     
    
            text1 BYTE "************* ASM *****************", 0
            text2 BYTE "*** Counting Nearly Matching Elements ***", 0
            text3 BYTE "the arrays are:...", 0
            text4 BYTE "Nearly Mathces were: ",0
    
    .code
    main PROC
    
            mov edx, offset text1                                                   ;hands the address of the firs char of text1
            call WriteString                                                                ;prints out text1
            call Crlf
            call Crlf
    
            mov edx, offset text2                                                   ; hands the address of the firs char of text1
            call WriteString                                                                ; prints out text1
            call Crlf
            call Crlf
    
            mov edx, offset text3                                                   ;hands the address of the firs char of text1
            call WriteString                                                                ;prints out text1
            call Crlf
    
            mov  esi,OFFSET Array1                                                  ; puts the offset of array in esi
            mov  ecx,arraySize                                                                      ; count = 6
            mov  ebx,TYPE Array1                                                   
            call DumpMem
            call Crlf
    
            mov  esi,OFFSET Array2                                                  ; puts the offset of array in esi
            mov  ecx,arraySize                                                                      ; count = 6
            mov  ebx,TYPE Array1                                                   
            call DumpMem
    
            mov eax,0
    
            ;here i use the registers to add 8 in to the stack addresses
            INVOKE CountNearMatches, ADDR Array1, ADDR Array2, diff, arraySize
    
            call Crlf
    
            mov edx, offset text4                                                   ;hands the address of the firs char of text1
            call WriteString                                                                ;prints out text1
    
            call WriteInt
            call Crlf
            call Crlf
            call WaitMsg                                                            ; Press any key to contineu...
            exit
    main ENDP
    
    ; ***************************************
    ; This is where the magic happnes!
    ; This function gets its parameters from
    ; the stack and counts the near mathches
    ; from the two arrays...
    ; ***************************************
    CountNearMatches PROC USES ebx edx esi edi,
            arr1:PTR SDWORD,                                                        ;points to the first array
            arr2:PTR SDWORD,                                                        ;points to the second array
            diff3:DWORD,                                                                    ;gets the diff from the stack
            aSize:DWORD
    
    ;-------------------------------------------------------
            mov edx, 0                                              ;index
            mov ecx, aSize
    myLoop:
    
            mov esi, arr1
            mov edi, arr2
            mov eax, [esi]
            mov ebx, [edi]
    
            sub eax,ebx
            cmp eax,diff3
            JLE myCount
           add arr1, 4
           add arr2, 4
            loop myLoop
    myCount:
        inc count
        add arr1, 4
        add arr2, 4
        loop myLoop
        mov eax, count
    
        ret
    CountNearMatches ENDP
    
    END main