Access to assembly language from C ++

This is my programming. I need to find the largest among an array of integers using a method written in the programming language 8086. This is my attempt:

  #include <iostream.h>
    #include <conio.h>

    int returnLargest(int a[])
    {
        int max;
        asm mov si,offset a

        for(int i=0;i<6;i++) //Assuming six numbers in the array...Can be set to a variable 'n' later
        {
              asm mov ax,[si]
              asm mov max,ax
              asm inc si
              cout<<max<<"\n";    //Just to see what is there in the memory location
        }

        asm mov si,offset a
        asm mov cx,0000h

        asm  mov dx, [si]

            asm mov cx,06h

        skip: asm   mov si,offset a
        asm mov bx,[si]
        asm        mov max,bx
        asm inc si
        abc: asm   mov bx,max
           asm     cmp [si],bx
        asm jl ok
           asm     mov bx,[si]
              asm  mov max,bx
        ok: asm loop abc
        asm mov ax,max
        return max;
    }
    void main()
    {
        clrscr();
        int n;
        int a[]={1,2,3,4,5,6};
        n=returnLargest(a);
        cout<<n; //Prints the largest
        getch();
    }

Expected response

1 2 3 4 5 6 6. But I get the following: enter image description here

Here I sit down and think ... Is this the value in the index i of the array actually stored in memory? Because, at least, we were taught that if a [i] is 12 (say), then the number 12 is written in the i-th memory cell.

Or, if the value is not stored in the memory cell, how can I write to the memory cell to perform the desired task?

I also ask you all to associate some materials with the web / paperback to refresh these concepts.

EDIT:

The same code in the assembly works fine ...

data segment
    a   db  01h,02h,03h,04h,05h,06h,'$'
    max db  ?
data ends

code segment
    start:
        assume cs:code,ds:data
        mov ax,data
        mov ds,ax

        mov si,offset a
        mov cx,0000h

        back:   mov dl,byte ptr [si]
                cmp dl,'$'
        je skip
        inc cx
                inc si
        jmp back

    skip:   mov si,offset a
                mov bl,byte ptr[si]
                mov max,bl
        inc si
        abc:    mov bl,max
                cmp [si],bl
        jl ok
                mov bl,[si]
                mov max,bl
    ok: loop abc
        mov al,max
        int 03h
code ends
    end start
+5
2

mov si,offset a . , int a[], . (a), (&a C, offset a ), mov si, a.

, inc si - si sizeof(int) .

:

++ (for loop, cout) . ++, , , . .

, . - , , push pop .

+7

, . (c-call stdcall - ). C/++.

, , , , , .

+3

All Articles