开发者

Syntax errors in my assembly code [closed]

开发者 https://www.devze.com 2023-04-06 17:02 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

I had this code and I was wondering if anyone would be willing to help me get it working.

TITLE MASM Template                     (main.asm)

; Description: this code is supposed to print out each letter followed by a space and then the capitalized version on seperate lines
; Revision date:

INCLUDE Irvine32.inc
.data

myArray byte 'l','s','d','t','h','c','f','u','c','k'    ;my array of 10 characters
.code
main PROC

    mov ecx,0                                        ;clears ecx
    mov ecx,LENGTHOF myArray                         ;should be 10
    mov edi,OFFSET myArray                   ;will point to the beginning of the array
    mov eax,0                                       ;clears eax
    mov esi,0                                       ;clears esi

LOne:

    mov eax,myArray[esi]          ;points the pointer at the beginning of myArray
    WriteChar eax                     ;prints the designated value in the array
    WriteChar 32                    ;prints a space (32 is the ascii value for ' ')
    sub eax,32                      ;subtracts 32 from the ascii value of the char
                         ;the capital version of each letter is -32 of its ascii value
    WriteChar eax           ;prints the capital version
    call CLRF               ;prints new line
    inc esi                 ;increments esi to the next array value
    dec ecx                 ;decrements ecx, moving it through the array

    loop LOne               ;loops back until ecx is equal to zero

    exit
main ENDP

END main

It won't compile giving me syntax e开发者_如何学JAVArrors.

1>main.asm(22): error A2008: syntax error : eax

1>main.asm(23): error A2008: syntax error : WriteChar

1>main.asm(26): error A2008: syntax error : eax

1>main.asm(21): error A2022: instruction operands must be the same size

1>main.asm(27): error A2006: undefined symbol : CLRF


Ah, Kip Irvine's book... I remember wanting to write my own library so I wouldn't have to use his...

You need to call those library functions, that's not how you do it in assembly languages.

Assuming his library hasn't changed since the 4th edition, WriteChar requires you to move the character you wish to write into the register al. Crlf doesn't require any arguments so you can just call it, but spelling matters. ;)

mov     al, BYTE PTR [edi + esi]
call    WriteChar                  ; print the character found at [edi + esi]

call    Crlf                       ; print a new line

After you get the syntax right, you'll want to double check your logic.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号