1. Subprogram design
Complete exercise 6.9.
The scores of 10 students are 76, 69, 84, 90, 73, 88, 99, 63100 and 80 respectively. Trial compilation
The number of people with 60-69 points, 70-79 points, 80-89 points, 90-99 points and 100 points is calculated by subprogram respectively
Store in units S6, S7, S8, S9, and S10.
DSEG SEGMENT GRADE DB 76,69,84,90,73,88,99,63,100,80,100 ;Points stored in GRADE Storage unit len dw $-GRADE SX DB 5 DUP(0) ;sx It is a fraction temporary accumulation unit S1 DB 0 ;S1 Store 60~69 Number of people in fractions S2 DB 0 ;S2 Store 70~79 Number of people in fractions S3 DB 0 ;S3 Store 80~89 Number of people in fractions S4 DB 0 ;S4 Store 90~99 Number of people in fractions S5 DB 0 ;S5 Deposit 100 points NOTICE DB 'INPUT A NUMBER',0DH,0AH,'$' DSEG ENDS CSEG SEGMENT ASSUME DS:DSEG,CS:CSEG ;Segment and code segment initialization STA:MOV AX,DSEG MOV DS,AX MOV DI,OFFSET GRADE ;DI Point to the selected fraction unit address MOV CX,len LEA SI,SX ;SI For operation of temporary accumulation unit AGIN:MOV AL,[DI] XOR BX,BX CALL COMP ;MOV AH,02H ;MOV DL,BL ;ADD DL,30H ; INT 21H ;Display the fraction segment of the temporary unit to be operated on the screen BL Content representation of INC BYTE PTR[SI+BX] ;Add 1 to the unit corresponding to the fraction segment where the score is INC DI LOOP AGIN XOR BX,BX ;The statistics content of the fraction segment of the temporary accumulation unit MOV AL,[SX+BX] MOV S1,AL INC BX MOV AL,[SX+BX] MOV S2,AL INC BX MOV AL,[SX+BX] MOV S3,AL INC BX MOV AL,[SX+BX] MOV S4,AL INC BX MOV AL,[SX+BX] MOV S5,AL ;Deposit separately S1,S2,S3,S4,S5 ; MOV AH,02H ; MOV DL,0AH ; INT 21H ; MOV AH,09H ; LEA DX,NOTICE ; INT 21H ; MOV AH,08H ;Enter the unit number of the fraction segment where you want to display the statistics, 1~5 Between ;INT 21H ; SUB AL,30H ; XOR BX,BX ; MOV BL,AL ; MOV AH,02H ; MOV DL,[SX+BX-1] ; ADD DL,30H ; INT 21H ;Display the number of people in the corresponding fraction segment according to the entered unit number MOV AH,4CH INT 21H ;Entry conditions, AL,BX;AL Store compared scores, BX Return fraction segment value ;Subroutine, which is used to compare the score segment and give the value of the segment to BX COMP PROC CMP AL,69 JA C1 JMP EXI C1:CMP AL,79 JA C2 INC BX JMP EXI C2:CMP AL,89 JA C3 ADD BX,2 JMP EXI C3:CMP AL,99 JA C4 ADD BX,3 JMP EXI C4:ADD BX,4 EXI:RET COMP ENDP CSEG ENDS END STA
2. Recursive subprogram design
Complete exercise 6.13.
Given a positive number N ≥ 1 stored in NUM unit, a recursive subroutine is developed to calculate FIB (N), and
Store the results in the RESULT cell.
Fibonacci number is defined as follows:
FIB(1)= 1
FIB(2)= 1
FIB(n)= FIB(n-2)FIB(n-1) n>2
3 3. Advanced assembly language technology
Complete exercise 7.11.
Try to write a program to complete the following functions: if the length of a string named X is greater than 5, the following refers to
Order will be compiled 10 times.
ADD AX, AX
(requirement: use conditional assembly, generate LST file during compilation, and view macro expansion)
DATAS SEGMENT ;Enter segment code here string db '1234567' len equ $-string ;Calculate string length DATAS ENDS STACKS SEGMENT ;Enter stack segment code here STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: MOV AX,DATAS MOV DS,AX ;Code snippet code here mov ax,1 IF len GT 5 REPT 10 ADD ax,ax ENDM ENDIF MOV AH,4CH INT 21H CODES ENDS END START
The result is 2^10 D=400H