Home

Find the Largest Number

Trying to find the yard with the most bones :)


        .MODEL SMALL
        .STACK 100h
        .DATA
            ;variables
            yards db 3, 7, 2, 9, 4, 9, 1, 6, 8, 5
            total db ?
            remainder db ?
            quotient db ?

            maxBones db 0
            yardIndex db 0
            currentIndex db 0

            ;Text
            totalTxt db 10,13,"Total Bones: $"
            bestTxt db 10,13,"Best Yard: $"
            bestTxtEnd db " bones)$"
        .CODE
        MAIN PROC

            ;1)Sum Total Bones
            MOV CX,10
            MOV SI,0
            MOV AX,0
            MOV SI, offset yards
            PROCESS_LOOP:
            ;1a)Sum Total Bones
            MOV BX,[SI]
            ADD AL,[SI]
            MOV DX,SI
            INC SI


            CMP BX,maxBones
            JLE NEXT
            MOV maxBones,BX
            MOV yardIndex,DX
            ;1b)Store Yard With Most Bones
            NEXT:
            LOOP PROCESS_LOOP
            MOV total,AL
            ;2)Print Total
            LEA DX, totalTxt
            MOV AH, 09h
            INT 21h

            ;2a)Print First Digit
            MOV AX,0
            MOV AL,total
            MOV BL,10
            DIV BL

            MOV remainder,AH
            MOV quotient,AL

            MOV DL, quotient
            ADD DL, 30h
            MOV AH, 02h
            INT 21h

            ;2b)Print Second Digit
            MOV DL, remainder
            ADD DL, 30h
            MOV AH, 02h
            INT 21h
            ;3)Print Best Yard

            ;Best yard: 3 (9 bones)
            LEA DX, bestTxt
            MOV AH, 09h
            INT 21h

            MOV DL, yardIndex
            ADD DL, 30h
            MOV AH, 02h
            INT 21h

            MOV DL, ' '
            MOV AH, 02h
            INT 21h
            MOV DL, '('
            MOV AH, 02h
            INT 21h
            MOV DL, maxBones
            ADD DL, 30h
            MOV AH, 02h
            INT 21h

            LEA DX, bestTxtEnd
            MOV AH, 09h
            INT 21h
            MOV AH, 4Ch
            INT 21h
        MAIN ENDP
        END MAIN