topic:
Enter two units of decimal number (between 0-7), require: 1) Two numbers of two numbers with hexadecimal output two numbers with four binary outputs, the difference must be greater than or equal to 03) Decimal output
analysis:
Assessment knowledge points:
The input basic mathematical operation of a single decimal number (addition / subtraction and multiplication / division) number of hexadecimal display digital binary display digital decimal display
Examination points:
Single decimal number input
Use the 01H DOS function to call, receive the data entered by the user in the AL middle code:
MOV AH, 01H INT 21h
Basic mathematical operation (addition / subtraction and multiplication)
Single non-symbolic addition / subtraction and multiplication, just use add, sub, mul
Digital hexadecimal display
The number is stored inside the computer, and there is a simple 4-digit control relationship between binary and hexadecimal relationship between the binary and hexadecimal:
Binary hexadecimal 10 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 011 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 f So, when displayed in hex, as long as you follow This control relationship will be stored in four binies in the machine to translate
Digital binary display
The number is stored in a binary in the computer, so the simplest and straightforward method is not required when displayed in binary, only one one is displayed, which can be displayed, the decimal display of numbers should be stored. The binary numbers inside the computer are displayed in decimal form. There are a variety of ways, with a better understanding of the practice. The core idea of this method is to display the number to display with its highest For the right, the displayer, the remainder is the same processing ... The final remainder changed to one, showing the last sale (in fact, the remainder itself). This practice has a drawback, it is operating Before you know the size of this binary, if you don't know the size, you can't find its highest power, you can only start from the possible maximum power, you should abandon all the merchants before the first non-harder. But This example is required to be displayed in two parties, so it is also displayed for the first zero.
The source code is as follows (see 1.asm):
Data segmentp1 db 'Input the 1st Num (0-7): $' P2 DB 'Input The 2st Num (0-7): $' Err DB 'Bad from AT! Input Again: $' Phe DB 'He (in h fromat : $ 'PCHA DB' CHA (IN B FROMAT): $ 'PJI DB' Ji (in d from): $ 'Nummin DB? Nummax DB? HE DB? Cha DB? JI DB? Nozero DB? Data Endscode Segmentassume CS : CODE, DS: DATASTART: MOV AX, DATAMOV DS, AXMOV DX, OFFSET P1CALL PROMPTLEA DI, NUMMINCALL INPUTLEA DX, P2CALL PROMPTLEA DI, NUMMAXCALL INPUTCALL SORTCALL MYADDCALL MYSUBCALL MYMULCALL DISPHECALL DISPCHACALL DISPJIMOV AH, 4CHINT 21H; ------- ---------------------- Mydiv Procpush CXXOR AX, AXMOV AL, BLDIV CLMOV BL, AHADD AL, 30HMOV DL, Almov AH, 02HINT 21hpop CxRetMydiv Endp; -------------------------------------------------------------------------------------------------------------------------------------------- ------- Dispji Procpush Axmov DX, Offset Pjicall Promptmov BL, Jimov Cl, 10Call MyDivmov Cl, 1Call MyDIVPOP DXPOP CXPOP BXPOP AXRETDISPJI ENDP; --------------- --------------; ----------------------------- Dispcha Procpush Axpush BXPUSH CXPUSH DXMOV DX, Offset Pchacall Promptmov BL, Chamov C L, 4SHL BL, CLMOV CX, 4NEXTBIT: ROL BL, 1MOV BH, BLAND BH, 01BJE DISP0DISP1: MOV DL, '1'MOV AH, 02HINT 21HJMP DISPCHACONTINUEDISP0: MOV DL,' 0'MOV AH, 02HINT 21HDISPCHACONTINUE: LOOP NEXTBITMOV DL , 'B'MOV AH, 02HINT 21HPOP DXPOP CXPOP BXPOP AXRETDISPCHA ENDP; -----------------------------;
----------------------------- Disphe Procpush Axpush CXPUSH DXMOV DX, OFFSET PHECALL PROMPTMOV BL, HEMOV CH, 2MOV Nozero, 0Next4bits: MOV CL, 4ROL BL, CLMOV AL, BLAND AL, 0FHCMP AL, 0AHJB DISPHEXADD AL, 07HDISPHEX: CMP AL, 0JNE DISPCMP nOZERO, 0JNE DISPJMP CONTINUEDISP: MOV nOZERO, 1ADD AL, 30HMOV DL, ALMOV AH, 02HINT 21HCONTINUE: SUB CH, 1JNE NEXT4BITSCMP NOZERO, 0JNE DISPHEXEXITMOV DL, 30HMOV AH, 02HINT 21DISPHEXEXIT: MOV DL, 'H'MOV AH, 02HINT 21HPOP DXPOP CXPOP AX RETDITDITISPHE ENDP; ------------------------------------------------------------------------------------------------------------------------------------ ----------; ----------------------------- Mymul Procpush Axxor AX, AXMOV Al, Numminmul Nummaxmov Ji, Alpop Axretmymul Endp; ------------------------------------------------------------------ --------------- Mysub ProCPush Axxor AX, AXMOV Al, NummaxSub Al, Numminmov Cha, Alpop AxretMysub Endp; ----------------- ------------; ----------------------------- Myadd Procpush Axpush DXMOV Al, Numminadd Al Nummaxmov He, Alpop DXPOP AXRETMYADD ENDP; ----------------------------; ------------------ Sort Procpush AXMOV Al, Nummincmp Al, Nummaxjbe SortexITXCHG AL, Nummaxxchg Al, NumminSortexit: Pop Axretort Endp; ------------------------------; --- --------------------------- Input Procpush AXPUSH DXINPUTSTART: MOV AH, 01HINT 21HCMP AL, 30HJB INPUTERRCMP AL, 37HJA INPUTERRSUB AL, 30HMOV [DI ], Aljmp InputExitinputer: Call CRLFMOV DX, Offset Errmov AH, 09HINT 21HCALL CRLFJMP INPUTSTARTINPUTEXIT: POP DXPOP AXRETINPUT ENDP; --------------------------- ---; ---------------------------- PROMPT Procpush Axcall CRLFMOV AH, 09HINT 21HCALL CRLFPOP AXRETPROMPT ENDP; ---- ------------------------------------- ------ CRLF Procpush DXPUSH AXMOV DL, 0DHMOV AH, 02HINT 21HMOV DL, 0AHMOV AH, 02HINT 21HPOP AXPOP DXRETCRLF ENDP
------------------------------------------------------- -----------------------------