-8

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 errors.

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

rkhb
  • 14,159
  • 7
  • 32
  • 60
Mattj7
  • 15
  • 1
  • 6
  • 3
    Ok, nevermind what the code does, seeing LSD, THC, and F*CK all together in a single SO post is a first for me! – Cᴏʀʏ Sep 23 '11 at 03:18
  • 2
    What's happening, and how does it differ from what you want/expect? I don't see any place that you're printing out a new-line, which the comments seem to indicate you probably want, but that's about the only problem that jumps out immediately. – Jerry Coffin Sep 23 '11 at 03:21
  • the code doesn't compile it says syntax error on lines 22,23,24,26 – Mattj7 Sep 23 '11 at 03:23
  • oh yea, I left out the new line code, call CLRF works right? not that that fixed the code any but thanks – Mattj7 Sep 23 '11 at 03:26
  • Whats not working exactly? Ask concise questions please. – Austin Henley Sep 23 '11 at 03:41
  • specifically, none of it is working lol. It won't compile, it says: 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 specifically, I want it to print out each letter, then a space, then the capital version of the letter and then a return, until it has done so for every element in the array. – Mattj7 Sep 23 '11 at 03:45

1 Answers1

2

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.

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
  • now the only thing keeping it from compiling are missing operators in the lines with "writeChar" I imported the irvine library so they should work, why is it saying missing operator? what could that mean – Mattj7 Sep 23 '11 at 04:02
  • and yea a lot of people are telling me bad things about kip irvine, which makes me feel terribly inconvenienced that thats the material my teacher is using to teach the class. He even uses kip's powerpoints! So apparently my entire understanding of this language is coming from this guy and what little internet resources i can find.... – Mattj7 Sep 23 '11 at 04:04
  • If you want another resource, check out [The MASM Forum](http://www.masm32.com/board/index.php). – Jeff Mercado Sep 23 '11 at 04:12