Accept two 4-digit hexadecimal number on the keyboard, and the next line is output in binary form. And the third to 0th and 15th to the 12th place in the result of this binary number, then output with hexadecimal output! I finally got it. I can't ask such a program in the forum!
Algorithm brief introduction:
To achieve such inputs and outputs, the key is to pay attention to the ASCII code (non-compressed BCD code) and the transformation of the compressed BCD.
Enter hexadecimal number: hexadecimal number includes a'b'c'd'e'f (in order to input easy to use lowercase), is called No. 1 call, so it is input to use a character. .
This way I want to set 8 variables to accept a total of 8 hexadecimal numbers. Of course, the received characters should be converted to the compressed BCD code, the code below the collective is an example:
MOV AH, 1; Turn 1 to call INT 21h MOV AH, 'A'; first registration; implement different selection CMP AH, Al JNA FUN14 JNC FUN15 FUN14: SUB AL, 57H; Here and lowercase A correspondence, such as A ASCII code value is 61h reduction 57h is 10 (a) jnc next2 fun15: Sub Al, 30h next2: MOV C, Al; final storage result
After accepting the next time, it is the same or the operation: the difference or operation: Due to the one of the accepts we just accept, then we can make an XOR operation with a bit. Save the result in the variable to output hexadecimal over the output of hexadecimal. The binary output is to simulate the process of dividing the two deposits, but to save the results every time, the result is the result of the result. Instance code: MOV DL, L; A calculation result add dl, 30h; convert to ACSII output (1 or 0); simulation divided by 2 balances MOV AH, 2 INT 21H MOV DL, K Add DL, 30H MOV AH, 2 INT 21H MOV DL, J Add DL, 30H MOV AH, 2 INT 21H MOV DL, I Add DL, 30H MOV AH, 2 INT 21H
The conversion is also simpler, that is, the first variable and the fourth variable are output. Instance code: MOV Al, P; P is the variable MOV AH, 10 of the four-digit binary bits, 10; why not think about 57h, it is also very easy to understand CMP AH, Al JNA FUNC0 JNC Func1 func0: Add Al, 57H JNC NEXTC0 FUNC1: Add Al, 30h Nextc0: Mov DL, Al Mov Ah, 2 INT 21H
; Specific code:
Data segment
Newline DB 0DH, 0AH, '$'
TOP1 DB 'The First Word (minuscule):', '$'
TOP2 DB 'THE Second Word (minuscule):', '$'
; the first word: abcd
A DB?
B DB?
C dB?
D DB?
The second: EFGK
e db?
F dB?
G DB?
H dB?
; TEMP VARIVABLE
I DB?
J DB?
K DB?
l db?
Save the xor result
M dB?
N DB?
o DB?
P DB?
Data ends
Code Segmentassume CS: Code, DS: DataStart: MOV AX, DATA MOV DS, AX; ************* TOP1 MOV DX, OFFSET TOP1 MOV AH, 9 INT 21H; **** ******* ENTER A MOV AH, 1 INT 21H MOV AH, 'A' CMP AH, Al JNA FUN0 JNC FUN1 FUNT0: SUB Al, 57H JNC NEXT0 FUN1: SUB AL, 30H NEXT0: MOV A, Al Download Adobe Reader *********** ENTER B MOV AH, 1 INT 21h MOV AH, 'A' CMP AH, Al JNA FUN2 JNC FUN3 FUN2: SUB AL, 57H JNC Next1 FUN3: SUB AL, 30H Next1: MOV B, Al; *********** ENTER C MOV AH, 1 INT 21h MOV AH, 'A' CMP AH, Al JNA FUN14 JNC FUN15 FUN14: SUB AL, 57H JNC Next2 FUN15: SUB AL, 30h next2: Mov C, Al; ********** Enter D MOV AH, 1 INT 21h MOV AH, 'A' CMP AH, Al JNA FUN4 JNC FUN5 FUN4: SUB AL, 57H JNC Next3 FUN5 : SUB Al, 30H Next3: Mov D, Al; ************* NewLine Mov DX, Offset Newline Mov Ah, 9 INT 21H; ************* TOP2 MOV DX, OFFSET TOP2 MOV AH, 9 INT 21H; *********** ENTER E MOV AH, 1 INT 21H MOV AH, 'A' CMP AH, Al Jna Fun6 JNC Fun7 Fun6: Sub Al, 57h JNC Next4 Fun7: Sub Al, 30h Next4: MOV E, Al; ******* **** Enter f Mov AH, 1 INT 21h MOV AH, 'A' CMP AH, Al JNA FUN8 JNC FUN9 FUNT5: SUB AL, 57H JNC Next5 FUN 9: SUB AL, 30H Next5: MOV F, Al; *** ******** ENTER G MOV AH, 1 INT 21h MOV AH, 'A'
CMP AH, Al JNA FUN10 JNC FUN11 FUN10: SUB AL, 57H JNC Next6 Fun11: Sub Al, 30h Next6: MOV G, Al; ********** ENTER H MOV AH, 1 INT 21H MOV AH , 'a' CMP AH, Al JNA FUN12 JNC FUN13 FUN12: SUB AL, 57H JNC Next7 Fun13: Sub Al, 30h Next7: MOV H, Al; ********* The Newline Mov DL, Offset Newline MOV AH, 9 INT 21h; ****** xor Function Mov Al, A MOV BL, E XOR Al, BL MOV M, Al Mov BL, 2; **** Enhance THE MOV AH, 0 DIV BL MOV I, AH; **** Can Use the for MOV AH, 0 DIV BL MoV J, AH MOV AH, 0 DIV BL MOV K, AH MOV L, Al; Pirnt (a xor e) The binary MOV DL, L AddD DL, 30H MOV AH, 2 INT 21H MOV DL, K Add DL, 30H MOV AH, 2 INT 21H MOV DL, J Add DL, 30H MOV AH, 2 INT 21H MOV DL, I Add DL, 30H MOV AH, 2 INT 21h; ****** XOR Function MOV Al, B Mov BL, F xor Al, BL MOV N, Al Mov BL, 2; **** Enhance THE MOV AH, 0 DIV BL MOV I, AH; **** Can Use the for MOV AH, 0 Div BL MoV J, AH MOV AH, 0 DIV BL MOV K, AH MOV L, Al; Pirnt (a xor e) The binary MOV DL, L Add DL, 30H MOV AH, 2 INT 21H MOV DL, K Add DL, 30H MOV AH, 2 INT 21H MOV DL, J Add DL, 30H MOV AH, 2 INT 21h MOV DL, I Add DL, 30H MOV AH, 2 INT 21h;
****** XOR Function MOV AL, C MOV BL, G XOR Al, BL MOV O, Al Mov BL, 2; **** Enhance THE MOV AH, 0 DIV BL MOV I, AH; *** * Can Use the for MOV AH, 0 DIV BL MOV J, AH MOV AH, 0 DIV BL MOV K, AH MOV L, Al; Pirnt (a xor e) The binary MOV DL, L Add DL, 30H MOV AH, 2 INT 21H MOV DL, K Add DL, 30H MOV AH, 2 INT 21H MOV DL, J Add DL, 30H MOV AH, 2 INT 21H MOV DL, I Add DL, 30H MOV AH, 2 INT 21H; ***** * xor function MOV Al, D Mov BL, H xor Al, BL MOV P, Al Mov BL, 2; **** Enhance THE MOV AH, 0 DIV BL MOV I, AH; **** CAN Use the for MOV AH, 0 Div BL MoV J, AH MOV AH, 0 Div BL MOV K, AH MOV L, Al; Pirnt (a xor e) The binary MOV DL, L Add DL, 30H MOV A H, 2 INT 21H MOV DL, K Add DL, 30H MOV AH, 2 INT 21H MOV DL, J Add DL, 30H MOV AH, 2 INT 21H MOV DL, I Add DL, 30H MOV AH, 2 INT 21H; ** ************ NEWLINE MOV DL, OFFSET NEWLINE MOV AH, 9 INT 21H; Print The 0x Result 'PNOM'
Al, P Mov AH, 10 CMP AH, Al JNA FUNC0 JNC Func1 Func0: Add Al, 57H JNC Nextc0 Func1: Add Al, 30H Nextc0: Mov DL, Al Mov AH, 2 INT 21H MOV Al, N Mov AH, 10 CMP AH, Al JNA FUNC2 JNC FUNC3 FUNC2: Add Al, 57H JNC Nextc1 Func3: Add Al, 30h Nextc1: MOV DL, Al Mov AH, 2 INT 21H MOV Al, O Mov AH, 10 CMP AH, Al JNA FUNC4 JNC FUNC5 FUNC4: Add Al, 57H JNC Next C2 Func5: Add Al, 30h Nextc2: Mov DL, Al Mov AH, 2 INT 21H MOV Al, M Mov AH, 10 CMP AH, Al JNA FUNC6 JNC FUNC7 FUNC6: Add Al, 57H JNC Nextc3 FUNC7: Add Al, 30H nextc3: MOV DL, Al Mov Ah, 2 INT 21h; ******* Move to Dos Mov AH, 4CH INT 21HCODE Endsend Start uses loops to do, to make the data, no Restrictions in 4 bits can be modified, if there are 4 places, you should first consider it!
Data segment
Stringn DB 5
STRINGL DB?
String DB 4 DUP (?), 0DH, 0AH, '$'
Stringn2 DB 5
STRINGL2 DB?
String2 DB 4 DUP (?), 0DH, 0AH, '$'
Result DB 4 DUP (?), 0DH, 0AH, '$'
Message1 DB 'please Input First Number:', 0DH, 0AH, '$'
Message2 DB 'please Input Second Number:', 0DH, 0AH, '$'
Newline DB 0DH, 0AH, '$'
N dw?
Data ends
Code Segmentassume CS: Code, DS: DataStart: Mov AX, Data MoV DS, AX; get the first string prompt Lea DX, Message1 MOV AH, 09H INT 21h; get the first string LEA DX, STRINGN MOV AH, 0AH INT 21H MOV CL, STRINGL MOV CH, 0; Screen Walking Lea DX, Newline Mov AH, 09H INT 21h; Get the first string prompt Lea DX, Message2 MOV AH, 09H INT 21h; get the first string LEA DX, STRINGN2 MOV AH, 0AH INT 21H; Since accepts non-compressed BCD code; So --- Convert MOV CX, 4 LOOP1: MOV Al, 4 SUB Al, Cl Mov AH, 0 MOV SI, AX CMP STRING [ Si], '0' JB Other CMP STRING [Si], '9' Ja Other Sub String [Si], 30H jmp next0 other: SUB STRING [SI], 37H Next0: loop loop1; Converting the second string MOV CX , 4 LOOP2: MOV AL, 4 SUB Al, Cl Mov AH, 0 MOV SI, AX CMP STRING2 [SI], '0' JB Other1 Cmp String2 [Si], '9' Ja Other1 SUB SUB SUB SUB STRING2 [SI], 30H J MP next1 Other1: SUB STRING2 [SI], 37H Next1: Loop Loop2; Transformation is completed, Different or MOV CX, 4 LOOP3: MOV Si, CX MOV Al, String [Si - 1] MOV BL, STRING2 [Si - 1 ] XOR Al, BL Mov Result [Si - 1], Al loop Loop3; Link Output Lea DX, Newline Mov AH, 09H INT 21H; Different or Complete Output Binary Results MOV CX, 4LOOP4: MOV AL, 4 SUB AL, CL Mov AH, 0 MOV SI, AX MOV Al, Result [Si] Next2: MOV AH, 0 MOV BL, 2 DIV BL CMP AL, 2 MOV BL, AH MOV BH, 0 PUSH BX INC N JB PRINT JMP NEXT2 PRINT: MOV AH, 0 Push AX INC N MOV BX, CX; Treatment to N;