;citim de la tastatura un array
;determinam maximul folosind o procedura
;long long maxim(long long *array, long long dim)
includelib libcmt.lib
includelib legacy_stdio_definitions.lib
printf proto
scanf proto
.data
read_prompt_dim   byte "Dati dimensiunea:",0
read_fmt_dim      byte "%lld",0
read_fmt byte "%lld",0
read_prompt_arr  byte "array[%lld]= ",0
mes     byte "max este %lld",0
dim sqword ?
array sqword 100 dup(?)
.code
main proc
;printf("Dati dimensiunea:")
sub rsp,40
lea rcx, read_prompt_dim
call printf
;scanf("%d",&num)
lea rcx,read_fmt_dim
lea rdx,dim
call scanf
add rsp,40

;rbx va contine adresa elementului curent al array
;rsi va contine indexul curent
lea rbx,array
mov rsi,0

begin_while:
;if(rsi>=dim) salt la final
;else citim element
    cmp rsi,dim
	jge end_while

;printf("array[%lld]",esi)	
	sub rsp,40
	lea rcx,read_prompt_arr
	mov rdx,rsi
	call printf
;scanf("%lld",&array[rsi])
;adresa array[esi] se afla in rbx
	lea rcx,read_fmt
	mov rdx,rbx
	call scanf
	add rsp,40

;incrementam rbx cu 8 (adresa urmatorului element din array)
;incrementam rsi
	add rbx,8
	inc rsi
jmp begin_while
end_while:
sub rsp,40
lea rcx,array
mov rdx,dim
call maxim

lea rcx,mes
mov rdx,rax
call printf
add rsp,40

ret
main endp
maxim proc
;long long maxim(long long *array, long long dim)
;rcx=&array, rdx=dim
;rax=[rcx]; for(r8=1;r8<rdx;r8++) if([rcx+8*r8]>rax) rax=[rcx+8*r8]
mov rax,[rcx]
mov r8,1
beg_wh1:
     cmp r8,rdx
     je end_wh1
	 cmp rax,[rcx+8*r8]
	 jge no_modif
	 mov rax,[rcx+8*r8]
	 no_modif:
	 inc r8
	 jmp beg_wh1
end_wh1:
ret
maxim endp
end

