0

I am working on a project right now where I have to perform matrix multiplication. I have indicated in the comment in the code below that I can not change the variables given and their type. Therefore, I can not switch to section .resb macro and I have to use section .data. I am trying to test out the program by comparing rAand cB first before performing the operation.

I decided to print strings to check if the program is working as it is intended. Apparently, the program deems that the two variables I am comparing are not equal when it is supposed to be the other way around. Did I misuse EAX and EBX?

%include "io.inc"
section .data
;Below variables are to be used. 
rA db 2

cA db 3

matrixA db 2,3,4

        db 1,0,0

rB db 3

cB db 2

matrixB db 0,127

        db 1,100

        db 0,10
section .text
global CMAIN
CMAIN:
    mov ebp, esp; for correct debugging
    ;write your code here
    
    lea eax, [rA]
    lea ebx, [cB]
    
    mov ax, [eax]
    mov bx, [ebx]
    
    
    cmp ax, bx ;this line is supposed to compare if both digits are equal
    JE bothEqual
    JNE notEqual
    
bothEqual:
    PRINT_STRING "Can be multiplied"
    NEWLINE
    
    PRINT_DEC 1, eax 
    NEWLINE
    PRINT_DEC 1, ebx
    jmp FINISH

notEqual:
    PRINT_STRING "Can not be multiplied"
    NEWLINE
    
    PRINT_DEC 1, eax ; Check the value of eax. [In this case, the expected value of eax = 2 but program prints 770]
    NEWLINE
    PRINT_DEC 1, ebx  ; Check the value of ebx. [In this case, the expected value of ebx = 2 but program prints 2]
    jmp FINISH 
    
FINISH:
    nop
    xor eax, eax
    ret
euriseth
  • 63
  • 6
  • I tried removing the double brackets but it only results in an error saying `error: invalid combination of opcode and operands`. – euriseth Dec 08 '20 at 16:54
  • Sorry, my bad. Taking a closer look... your `rA`, `rB`, `cA` and `cB` are all defined as byte with `db`, but you are moving and comparing 16-bit values, e.g., `mov ax, [eax]` and `cmp ax, bx`. You should use `mov al, [eax]` and `mov bl, [ebx]` then `cmp al, bl`. Or you can leave the instructions alone and define those items with `dw` instead of `db`. – lurker Dec 08 '20 at 18:23

0 Answers0