Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

I keep getting the following error, “invalid instruction operands”, when using macros mPrtStr.

I am currently working on a assembly language lab for my class. The lab is supposed to be done in x64, 64 bit assembly language. But I am currently getting an error when trying to compile my code. The error is "invalid instruction operands" and it happens several times throughout the code, only when I use the macros defined at the top of the code (mPrtStr, mPrtChar, mPrtChar). Everytime I use

mPrtStr stringName

I get an error.

This is the following code please help:

;Due Date: Monday December 3
;30 points

;NOTE: program will not compile until you define the EXPRESSION struct below

;You should include kennedyDspFloat.lib and Irvine32.lib in your project
;For examples of using DspFloat see DspFloat.asm

;Your output should follow the order given below:

;Title (no blank line before the title)
;blank line
;expression1
;expression2
;rest of expressions, each on a separate line
;blank line
;ending messages in the order below, each on a separate line

;Sample output (Substitute your name for my name)
;Your output will be different since the expressions you are evaluating are 
;different and the field width is different. 

;Program 8 by Fred Kennedy
;
;   20.56 -  10.09 =  10.47
;  178.45 / 104.34 =   1.71
;  674.32 + -15.85 = 658.47

;   The size of the expressions array in bytes is: 72
;    The size of an EXPRESSION struct in bytes is: 24
;The number of EXPRESSION structs in the array is: 3

;To print the '=' you should print a space then the '='.
;NOTE: The spacing after the '=' is supplied by the field width of 
;the result so don’t print a space after the '=' only print a single space before the '='.

;The string to print "space =" has already been defined for you in the data section
;of this file so all you have to do is print it.

;Submission
;  Email the instructor the following item as an email attachment:  
;
;  prog8FloatFA18Student.asm (use exact file name)

;*******************MACROS********************************

;NOTE: Use the macros below to print strings, single chars and decimal numbers
;Do not define any other macros.

;mPrtStr will print a zero terminated string to the soncole
mPrtStr  MACRO  arg1            ;arg1 is replaced by the name of string to be displayed
         push edx               ;save edx
         mov edx, offset arg1   ;address of str to display should be in dx
         call WriteString       ;display 0 terminated string
         pop edx                ;restore edx
ENDM

;mPrtChar will print a single char to the console
mPrtChar MACRO  arg1            ;arg1 is replaced by char to be displayed
         push eax               ;save eax
         mov  al, arg1          ;al = char to display
         call WriteChar         ;display char to console
         pop  eax               ;restore eax
ENDM

;mPrtDec will print a dec number to the console
mPrtDec  MACRO  arg1            ;arg1 is replaced by the name of string to be displayed
         push eax               ;save eax
         mov  eax, arg1         ;eax = dec num to print
         call WriteDec          ;display dec num to console
         pop  eax               ;restore eax
ENDM



;*************************PROTOTYPES*****************************

ExitProcess PROTO       ;to exit to dos with exit code

ReadChar PROTO          ;Irvine code for getting a single char from keyboard
                        ;Character is stored in the al register.
                        ;Can be used to pause program execution until key is hit.

WriteDec PROTO          ;Irvine code to write number stored in eax
                        ;to console in decimal

WriteString PROTO       ;Irvine code to write null-terminated string to output
                        ;EDX points to string

WriteChar PROTO         ;write the character in al to the console

;To call SetFloatPlaces, SetFieldWidth or DspFloat in your program you must first include
;kennedyDspFloat.lib in your project

SetFloatPlaces PROTO    ;sets the number of places a float should round to while printing 
                        ;The default place is 1.
                        ;populate ecx with the number of places to round a floating point num to
                        ;then call SetFloatPlaces.
                        ;If the places to round to  is 2 then 7.466
                        ;would display as 7.47 after calling DspFloat
                        ;The places to round to does not change unless
                        ;you call SetFloatPlaces again.



DspFloat PROTO          ;prints a float in st(0) to the console formatted to a field width and rounding places.
                        ;DspFloat pops the floating point stack.
                        ;DspFloat does not check if the number is a valid float.

SetFieldWidth PROTO     ;Set the space a float should occupy when printed.
                        ;Populate ecx with the total space you want want a displayed float to occupy.
                        ;Use this to help right justify a displayed float to line up a column of numbers vertically
                        ;The default field width is 0.
                        ;To change the field width from the default call SetFieldWidth before calling DspFloat.

;************************  Constants  ***************************

    LF       equ     0Ah                   ; ASCII Line Feed


;************************  Structs  ***************************

    ;NOTE: before you do anything else you must define the EXPRESSION struct
    ;as described below.

    ;The EXPRESSION struct contains information for one expression
    ;operand1 operator operand2 (5.6 + 2.1)
    ;
    ;Define an EXPRESSION struct with the following data in the following order
    ;
    ; operator uninitialized byte
    ; align real8
    ; operand1 uninitialized real8
    ; operand2 uninitialized real8

    EXPRESSION struct

        operator byte ?
        align real8
        operand1 real8 ?
        operand2 real8 ?

    EXPRESSION ends

    ;************************DATA SEGMENT***************************

.data

    ;NOTE: do not change the strings below except to add LFs for line spacing
    ;and to change my name to your name.

    heading                     byte   "Program 8 by Jared Childers", LF, LF,0
    equals                      byte    " =",0

    sizeofEXPRESSIONmsg         byte LF, "    The size of an EXPRESSION struct in bytes is: ",0
    sizeofexpressionsArrayMsg   byte LF, LF, "   The size of the expressions array in bytes is: ",0
    numOfexpressionsMsg         byte LF, "The number of EXPRESSION structs in the array is: ",0

    ;expressions is an array of EXPRESSION structs initialized with data

    ;The order in the struct is operator, operand1, operand2
    ;The first expression is -35.56 + 10.089
    ;NOTE: Do not change the data in the array.

    align real8 ;align the first struct on a real8 boundary
    expressions EXPRESSION {'+',-35.56,10.089},{'/',78.45,104.34},{'*',5674.32,-10.56},{'-',678.12,789.77},{'/',0.0,104.34}

    ;EXPRESSION_COUNT will be equal to the number of EXPRESSION structs in the array
    ;You should use EXPRESSION_COUNT when you print out the number of structs in the array
    EXPRESSION_COUNT equ lengthof expressions

    ;TOTAL_SIZE will be equal to the total bytes in the array
    ;You should use TOTAL_SIZE as the termination condition for the loop in main
    TOTAL_SIZE equ sizeof expressions
;************************CODE SEGMENT****************************

.code

main PROC

    mov ecx, 2                              ;sets the amount of places to round to in ecx.
    call SetFloatPlaces                     ;set the float places to 2

    mPrtStr heading                     ;moves the heading title into edx for output

    xor rbx, rbx                            ;initializes loop variable to 0

    loopTop:
        cmp rbx, TOTAL_SIZE                 ;cmp ebx to the size of the birthDays array
        jae DONE                            ;if ebx >= size of the brithDays array then done 

        mov rcx, 8                          ;mov 8 into ecx 
        call SetFieldWidth                  ;sets the field width for operand1


        fld expressions[rbx].operand1       ;push operand1 onto stack
        call DspFloat                       ;displays the float on st(0)

        mPrtChar ' '                        ;add space into al

        mPrtChar expressions[rbx].operator  ;print char '='
        mov al, expressions[rbx].operator   ;moves the operator at the array index into al

        mov ecx, 7                          ;mov 7 into ecx 
        call SetFieldWidth                  ;sets the field width for operand2

        fld expressions[rbx].operand2       ;push operand2 onto stack
        call DspFloat                       ;displays the float on st(0)

        fld expressions[rbx].operand1       ;push operand1 onto stack
        fld expressions[rbx].operand2       ;push operand2 onto stack

        cmp al, '*'                         ;compare al to '*'
        jne SUBT                            ;if not equal proceed to compare
        fmul                                ;will multiply st(1) * st(0) = st(0)
        jmp DONE2                           ;jump to done2

        SUBT:
            cmp al, '-'                     ;compare al to '-'
            jne ADDI                        ;if not equal proceed to compare 
            fsub                            ;will sub st(1) - st(0) = st(0)
            jmp DONE2                       ;jump to done2

        ADDI:
            cmp al, '+'                     ;compare al to '+'
            jne DIVI                        ;if not equal proceed to compare
            fadd                            ;will add st(1) + st(0) = st(0)
            jmp DONE2                       ;jump to done2

        DIVI:
            fdiv                            ;will divide st(1) / st(0) = st(0)

        DONE2:

        mPrtChar equals                     ;output equals sign 

        mov ecx, 10                         ;mov 10 into ecx 
        call SetFieldWidth                  ;sets the field width for result

        call DspFloat                       ;displays the float on st(0), which is the result 

        mPrtChar LF                         ;print nextline

        add ebx, sizeof EXPRESSION          ;add size of EXPRESSION struct to ebx to address next 
                                            ;struct in expressions array
        jmp loopTop                         ;repeat loop

    DONE:

    mPrtStr sizeofexpressionsArrayMsg       ;sizeofexpressionsArrayMsg moved to edx for printing 

    mov al, TOTAL_SIZE                      ;move the expression count into al
    call WriteChar                          ;call WriteString to print string in edx 

    mPrtStr sizeofEXPRESSIONmsg             ;sizeofEXPRESSIONMsg moved to edx for printing       

    mov al, sizeof EXPRESSIONS              ;move the expression count into al
    call WriteChar                          ;call WriteString to print string in edx 

    mPrtStr numOfexpressionsMsg             ;numOfexpressionsMsg moved to edx for printing      

    mov al, EXPRESSION_COUNT                ;move the expression count into al
    call WriteChar                          ;call WriteString to print string in edx 

    call    ReadChar                        ;pause execution
    call    ExitProcess                     ;exit to dos: like C++ exit(0)

main ENDP

END 

Comments