vendredi 23 novembre 2018

How to convert this C++ code to Assembly Using If and While?

Hello so I've been working on this homework where we have to convert:

int array[] = {56,1,12,9,34,23,61,18,105,22};
 int max = 0;
 int ArraySize = sizeof array / sizeof max;
 int index = 0;

 while ( index < ArraySize )
 {
 If ( array[index] > max )
 max = array[index];
 index++;
 }

into assembly. This is what I have so far:

.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:WORD

.data
Array WORD 56, 1, 12, 9, 34, 23, 61, 18, 105, 22
max WORD 0
ArraySize WORD 0
index WORD 0

.code
main proc
    mov ArraySize, SIZEOF Array
top:    cmp index, ArraySize
        jb next
        mov max, Array[index]
        inc index
        jmp top
next:    cmp Array[index], max
        ja next1
next1:    mov max, Array[index]


    invoke ExitProcess,0
main endp
end main

I'm struggling to see how this here is wrong because when I debug I get an error message. Any help would be great.

Aucun commentaire:

Enregistrer un commentaire