asm find the smallest value in arrayA in assembler COMP375
Solution
#include <iostream>
 using namespace std;
int main(int argn, char *argv[]) {
    int smallest, i, arrayA[8];
    cout << \"Enter 8 numbers\" << endl;
    for(i=0; i<8; i++) {
        cin >> arrayA[i];
    }
    _asm {
                push rbp
                mov rbp, rsp
                mov QWORD PTR [rbp-24], rdi
                mov rax, QWORD PTR [rbp-24]
                mov eax, DWORD PTR [rax]
                mov DWORD PTR [rbp-4], eax
                mov DWORD PTR [rbp-8], 1
                jmp .L2
        .L4:
                mov eax, DWORD PTR [rbp-8]
                cdqe
                lea rdx, [0+rax*4]
                mov rax, QWORD PTR [rbp-24]
                add rax, rdx
                mov eax, DWORD PTR [rax]
                cmp eax, DWORD PTR [rbp-4]
                jge .L3
                mov eax, DWORD PTR [rbp-8]
                cdqe
                lea rdx, [0+rax*4]
                mov rax, QWORD PTR [rbp-24]
                add rax, rdx
                mov eax, DWORD PTR [rax]
                mov DWORD PTR [rbp-4], eax
        .L3:
                add DWORD PTR [rbp-8], 1
        .L2:
                cmp DWORD PTR [rbp-8], 7
                jle .L4
                pop rbp
                ret
    }
    cout <<\"The smallest value is \" << smallest << endl;
    return 0;
 }

