;These are the examples I did in class ;writeString - Pass argument by address ;moveCursor - Pass arguments by value, only retrieve bytes from the stack ;calcTotal - Pass arrayLength by value, array by address. ; Returns the total in AX ;findX - Pass min by address, max by address, ; arrayLength by value, array by address ; Changes the values of min and max from within the procedure .model small .186 .stack 100h .data array dw 100,200,30,400,700,600 arrayLength dw ($-array)/(size array) msg db "The total of all the numbers is $" msgMax db "The max of all the numbers is $" msgMin db "The min of all the numbers is $" crlf db 0dh,0ah,"$" max dw ? min dw ? .code include Asm_io.inc main proc mov ax,@data mov ds,ax call clearScreen call findTotal call findMinMax push 24 push 0 call moveCursor add sp,2 mov ax,4c00h int 21h main endp clearScreen proc push ax push bx push cx push dx mov ah,06h mov al,0 mov bh,0 mov cx,0 mov dx,184Fh int 10h pop dx pop cx pop bx pop ax ret clearScreen endp findTotal proc push bp mov bp,sp push ax push 10 ;push the row by value push 20 ;push the column by value call moveCursor add sp,4 ;remove the parameters push arrayLength ;pass size by value push offset array ;pass array by address call calcTotal add sp,4 ;remove the parameters push 10 push 20 push offset msg ;pass string by address push ax call printValue add sp,8 ;remove the parameters pop ax mov sp,bp ;remove local variable pop bp ret findTotal endp findMinMax proc push bp mov bp,sp push offset min ;pass min by address push offset max ;pass max by address push arrayLength ;pass size by value push offset array ;pass array by address call findX add sp,4 ;remove the parameters push 11 push 20 push offset msgMax push max call printValue add sp,8 push 12 push 20 push offset msgMin push min call printValue add sp,8 mov sp,bp ;remove local variable pop bp ret findMinMax endp printValue proc push bp mov bp,sp push ax push [bp+10] ;push the row by value push [bp+8] ;push the column by value call moveCursor add sp,4 ;remove the parameters push [bp+6] ;pass string by address call writeString add sp,2 ;remove the parameter mov ax,[bp+4] ;retrieve value from stack call print_signed push offset crlf ;pass string by address call writeString add sp,2 ;remove the parameter pop ax mov sp,bp pop bp ret printValue endp moveCursor proc push bp mov bp,sp push dx push ax push bx mov dl,[bp+4] ;retrieve the row. Only one byte is retrieved mov dh,[bp+6] ;retrieve the column. Only one byte is retrieved mov ah,02h mov bh,0 int 10h pop bx pop ax pop dx mov sp,bp pop bp ret moveCursor endp writeString proc push bp mov bp,sp push dx push ax mov dx,[bp+4] ;retrieve the address of the string mov ah,09h int 21h pop ax pop dx mov sp,bp pop bp ret writeString endp calcTotal proc push bp mov bp,sp push cx push bx mov bx,[bp+4] ;load the address of the array mov cx,[bp+6] ;load the sizr of the array xor ax,ax ct_top: add ax,[bx] ;use address in bx to reference the array add bx,2 loop ct_top pop bx pop cx mov sp,bp pop bp ret calcTotal endp findX proc push bp mov bp,sp push ax push bx push cx push dx mov bx,[bp+4] ;load the address of the array mov cx,[bp+6] ;load the sizr of the array mov dx,[bx] ;initialize max mov ax,[bx] ;initialize min add bx,2 dec cx jz fx_done fx_top: cmp dx,[bx] ;test for new max jge fx_min mov dx,[bx] ;set new max jmp fx_next fx_min: cmp ax,[bx] ;test for new min jle fx_next mov ax,[bx] ;set new min fx_next: add bx,2 loop fx_top fx_done: mov bx,[bp+8] ;get address of max mov [bx],dx ;save max value to max variable mov bx,[bp+10] ;get address of max mov [bx],ax ;save max value to max variable pop dx pop cx pop bx pop ax mov sp,bp pop bp ret findX endp end main