1

I'm trying to concert the following pseudocode into assembly code- enter image description here

This is the code that I currently have. While the code builds successfully, it's going through both the LESSER and GREATER conditions when debugging. I can't seem to figure out what's making this happen. Any help will be appreciated. Thank you.

.data
    array1 BYTE 13h,14h,15h,16h
    array2 BYTE 12h,13h,14h,15h
    sample1 BYTE 30h
    sample2 BYTE 5h
    length1 BYTE LENGTHOF array1
    length2 BYTE LENGTHOF array2
    index BYTE 0
    maxlength DWORD 4
    exp1 WORD ?

.code
main PROC
    mov esi, 0  ;serves as the index
    L1:
    mov bl, array1[esi]
    mov cl, array2[esi]
    cmp bl, cl
    jg GREATER
    jl LESSER

    GREATER: 
    mov al, bl
    mul sample1
    mov bx, ax
    mov al, cl
    mul sample2
    mov cx, ax
    mov ax, bx
    mov dx, 0
    div cx

    LESSER:
    mov exp1, 0

    inc esi
    cmp esi, maxlength  ;while condition
    jl L1
trufflewaffle
  • 179
  • 10
  • 3
    The cpu does not know about blocks. After the `div cx` it will continue to the next instruction, which happens to be in the `LESSER:` case. You will need to add a jump to skip that block. PS: you don't seem to store the result in `exp1`. – Jester Apr 08 '21 at 23:58
  • @JesterWould it work if I reversed the jump conditions? – trufflewaffle Apr 09 '21 at 00:31
  • 2
    No, it would have the same problem. – Jester Apr 09 '21 at 00:43

0 Answers0