40 likes | 142 Views
CS 206D Computer Organization Lab7. MODEL SMALL . STACK 100H . DATA PROMPT_1 DB 0DH,0AH,'Enter a number in binary form ( max 4-bit )$' PROMPT_2 DB 0DH,0AH,'The Average of the 4 numbers in Hexadecimal form is : $' Total DW ? . CODE MAIN PROC
E N D
CS 206D Computer Organization Lab7 CS 111
MODEL SMALL .STACK 100H .DATA PROMPT_1 DB 0DH,0AH,'Enter a number in binary form ( max 4-bit )$' PROMPT_2 DB 0DH,0AH,'The Average of the 4 numbers in Hexadecimal form is : $' Total DW ? .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX MOV CX , 4 XOR BX,BX ;Clear bx
READ: ;Loop label to read 4 numbers in binary form ;print PROMPT_1 the message LEA DX, PROMPT_1 MOV AH, 9 INT 21H MOV AH,1 ;read char INT 21H WHILE_: CMP AL, 0DH ; CR? JE ReadNext;Yes, done AND AL,0FH ; no , convert char to binary SHL BX , 1 ;make room for the new bit OR BL,AL ;put value into BX INT 21H ; read again JMP WHILE_ ReadNext: ADD TOTAL,BX XOR BX,BX ;Clear bx LOOP READ
;calculate avarge MOV cl , 4 MOV ax,TOTAL DIV CL MOV BL , AL PRTINT_HEX: LEA DX, PROMPT_2 ; load and display the string PROMPT_2 MOV AH, 9 INT 21H MOV CX, 4 ; initialize loop counter MOV AH, 2 ; set output function Display: ;loop lable MOV DL, BH SHR DL,4 CMP DL , 9 ; DL <=9? JBE DIGIT ;yes, it is digit ADD DL, 37H ; no, it is letter JMP print_char DIGIT: OR DL, 30H print_char: INT 21H ROL BX,4 LOOP Display