What's wrong with my code?

When I try to compiled part 2 of the test:

[code]

TITLE Test2 (part 2) (test2.asm)

; Program Description:
; Author:
; Date Created:
; Last Modification Date:

INCLUDE Irvine32.inc

.data

arrayB db 54h,26h,39h,A2h

arrayW dw 9876h,1234h

arrayD dd 33445566h

arrayE dd 8 DUP(0)

arraySize = ($-arrayE) / (TYPE arrayE)


.code
main PROC

mov ax,arrayW+2 ; AX = __________

mov cl,arrayB+1 ; CL = ______

mov dx,WORD PTR arrayB ; DX = __________

mov di,offset ArrayW

mov ax,[di+2] ; AX = __________

mov ax,[di+4] ; AX = __________

mov eax,[di] ; EAX = __________

mov bx,arrayW

movzx edx,bx ; EDX = _______



;Write the decimal value of each destination operand:

mov ax,TYPE arrayD ; AX = ____

mov dx,LENGTHOF arrayE ; DX = ____

mov cx,SIZEOF arrayE ; CX = ____

mov dx,arraySize ; DX = ____



exit ; exit to operating system
main ENDP


END main
[/code]

The assembler gives me these errors:

Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000. All rights reserved.

Assembling: test2.asm
test2.asm(40) : error A2155: cannot use 16-bit register with a 32-
bit address
test2.asm(42) : error A2155: cannot use 16-bit register with a 32-
bit address
test2.asm(44) : error A2155: cannot use 16-bit register with a 32-
bit address
test2.asm(38) : error A2022: instruction operands must be the same
size
test2.asm(16) : error A2006: undefined symbol : A2h
Press any key to continue . . .


I also wanted to ask if following data types are in Irvine32.lib and
what do they mean. I think dw = dword but I'm not sure about db
and dd.

arrayB db 54h,26h,39h,A2h

arrayW dw 9876h,1234h

arrayD dd 33445566h

arrayE dd 8 DUP(0)

Thanks in advance...


Comments

  • Your code generates some arrays with different numbers of elements and different operandsizes.the errors results from mixing up the address and the content of a array-member.i ve added the declaration in c-syntax:

    : arrayB db 54h,26h,39h,A2h <- BYTE arrayB[4]
    :
    : arrayW dw 9876h,1234h <- WORD arrayW[2]
    :
    : arrayD dd 33445566h <- DWORD arrayD
    :
    : arrayE dd 8 DUP(0) <- DWORD arrayE[8]

    db means definebyte,dw = define word and dd define doubleword.
    the DUP-operator generates multiple elements of the requested size:

    dd 20 dup(0) <- 20 dwords = 20*4=80 bytes

    last but not least there is a different between:

    mov eax,OFFSET arrayD <- address
    and mov eax,[arrayD] <- content

    its in most cases better to read and understand,when using [] to access memory-content and offset to get the address,because theres not the risk ti mix something up.
  • [blue]Also, the HEX constants starts with zero if the first digit is from set: "ABCDEF", so A2h should be 0A2h.[/blue]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories