Current location - Loan Platform Complete Network - Big data management - [High score] Help to make an assembly language program: student achievement statistics.
[High score] Help to make an assembly language program: student achievement statistics.
; Program operating instructions:

; 1. Definition of this program: the maximum name is 20 characters, the maximum student number is 10 characters, and the maximum score is 3 digits.

; 2. When the student information is entered, it will automatically end when the information is sufficient; When the number of digits is not enough, press Enter to end.

; 3. When you enter a name, if you enter it directly, it means that the student information input is over and the information processing is entered.

; The program is compiled and debugged in the integrated environment of MASMPlus 1.2, and runs correctly.

code segment

Suppose CS:Code, DS:Code

; -

; Function: displays the string (Str_Addr) at the specified address.

; Entrance:

; Str_Addr= = String address (required in data segment)

; Usage: output string address

; Usage example: Output PromptStr

Output macro string address

Lea dx, Str _ address

mov ah,9

int 2 1h

EndM

; -

; Function: output a character.

; Entry: dl= character to be displayed

Near Output_Chr proc

Push axe

mov ah,02h

int 2 1h

Bangalore torpedo

Soak in water to soften

Output _Chr endp

; -

; Function: output carriage return and line feed

Output _CTLF approach

Push axe

Push dx

mov ah,02h

mov dl,0dh

int 2 1h

mov dl,0ah

int 2 1h

Popular dx

Bangalore torpedo

Soak in water to soften

Output _CTLF endp

; -

; Function: take the cursor position

; Entrance: None

; Exit: DH= line number, DL= column number.

Near GetCursor Proc

Push axe

Push BX

Push CX

BX XOR BX

MOV, 3

INT 10H

MOV cursor _ line, DH

MOV cursor _Col, DL

Pop CX

Pop bx

Bangalore torpedo

Soak in water to soften

Cursor_Row DB?

Cursor _Col DB?

Get cursor end

; -

; Function: Set cursor position

; Entry: Cursor_Row= row coordinates; Cursor _ column: column coordinates)

SetCursor forward to nearby.

Push CX

Push BX

Push axe

MOV DH,Cursor_Row

MOV DL, cursor _ column

BX XOR BX

MOV, 2

INT 10H

Bangalore torpedo

Pop bx

Pop CX

Soak in water to soften

End of SetCursor

; -

; Function: Enter the decimal number with the specified number of digits on the keyboard, convert it into binary number and save it in the specified storage unit.

; Because the maximum data type is limited to word, the maximum number of digits is 5 and the maximum number of unsigned digits is 65536.

; Convention: Enter directly as the number 0.

; Entry: @@Digits= digits; Di= Save the first address of the input number.

; @@Type_Data= saved data type, B= byte type, W= word type.

; Exit: the converted binary number is stored in the unit indicated by di.

The Input_Digit process is approaching.

CR equ 000DH

If equ 000AH

KBBack equ 0008H

Push dx

Push cx

Push bx

Push di

lea di,@@Save_Tmp

Push di

cld

Mov cl, @ @ digits

XOR ch, ch

Push cx

@@Input: Call GetCursor to get the cursor position.

Mov,1; Accept a character from the keyboard.

int 2 1h

Cmp aluminum and chromium; If you type carriage return, you type fewer than n digits.

Jz @ @ ASC _ Dec turn to the number that has been entered.

cmp al,KBBack

Jz @ @ KB _ Back If it is a blank key, please re-enter.

cmp al,' 0 '

Jb @ @ KBBack If it is less than the number "0", please re-enter.

cmp al,' 9 '

Ja @ @ KBBack If it is less than the number "9", please re-enter.

jmp @@Save_Dig

@@KB_Back: dec Cursor_Col

inc cx

December 2 nd

@@KBBack: Call the cursor position of SetCursor.

Jmp @ @ input

@@Save_Dig: and al, 0fh are converted into binary numbers.

Stosb protection

Loop @ @ Input accepts the next number.

@@ASC_Dec: mov ax,cx

Popular cx

Pops

Child cx, ax; Number of digits actually entered

XOR bp, bp

xor dx,dx

Xor ax, ax

Jcxz @ @ Save _ Ret If you enter directly without entering any numbers, please press enter' 0'.

Dec cx actually reduces the number of digits input by 1, and this string of input digits can be converted into binary digits.

Jcxz @ @ One _ Digit If the number entered is only one digit, directly save the binary number.

mov bx, 10

@@Mul_Ten: lodsb

Bytes expand into words.

Add ax, bp

Multiple bx

Mobile bp, ax

loop @@Mul_Ten

@@One_Digit: lodsb

Bytes expand into words.

Add ax, bp

@@Save_Ret: pop di

cmp @@Type_Data,' B '; Byte type?

Jamaican dollar +5

stosw

jmp $+3

stosb

pop bx

Popular cx

Popular dx

Soak in water to soften

@@Digits db? ; Decimal number

@ @ Type _ Data db' B saved data type. B= byte type, W= word type.

@@Save_Tmp db 16 dup(? )

Input _ number EndP

; -

; Function: Convert the binary unsigned number in AX into explicit decimal ASCII code and send it to the display screen for display.

; Entry: AX= binary number

; Exit: displays the converted ASCII code at the current cursor position.

Near Dec_ASCII Proc

Push dx

Push bx

Push di

mov bx, 10

lea di,@@Temp_Save[6]

Mov byte pointer [di],' $'

December 2 nd

@@Divide: xor dx,dx

Branch bx

Or dl, 30h

mov [di],dl

December 2 nd

Test ax, 0ffffh

Jnz @ @ Divide

Company di

Push di

Popular dx

mov ah,9

int 2 1h

Popdi

pop bx

Popular dx

Soak in water to soften

@@Temp_Save db 7 dup(? )

Dec_ASCII EndP

; -

; Function: convert the binary unsigned number in AL as decimal into explicit decimal ASCII code,

; And sent to the display screen, regardless of rounding.

; Entries: AH= binary number, BH= divisor, CX= reserved decimal places.

; Exit: displays the converted ASCII code at the current cursor position.

Dec_Frac process approaching

Push axe

mov dl,'.'

Call Output _ Chr to display decimal point.

Bangalore torpedo

mov bl, 10; multiplier

@@Dec_Frac: mov al,ah; The remainder is not 0, and the decimal part is processed.

Mul bl multiplies the remainder by 10 and continues the division.

Div bh is divided by the divisor, and the quotient is taken as one decimal place of the result.

Or aluminum, 30h

mov dl,al

Call Output _ Chr to display a decimal place.

Loop @@Dec_Frac

Soak in water to soften

End of Dec_Frac

; -

Name _ Length equ 20 name length

ID _ Length equ 10; Student number length

Info _ student structure; Types of students' information structure

Name_Student db Name_Length dup(? ) ; (full name)

ID _ student database ID _ length dup (? ) ; Student number

Score _ student db? ; achievement

Information _ Student End

; -

Prompt_Str db 7,' Name ',Name _ Length-4+2 dup(20h); Name title string

DB' Student ID', 2 dup (20h); Student ID title string

Db' score', CR, lf; Score title string

Database Name _ Length Duplicate ('-'), 2 Duplicate (20h)

Database ID _ Length Duplicate ('-'), 2 Duplicate (20 hours)

db 5 dup('-'),CR,LF,' $ '

Temp_Cursor dw? ; Input and display the cursor position of student information.

prompt_Ave db CR,LF,' Average:$ '; Prompt display average score

Buffer_Data db? ,? ,Name_Length+2 dup(? ) ; Name and student number input buffer

Press the key db CR, LF, CR, LF,' press any key to exit ... $'

Start: push cs

Popular digital camera

Push cs

Pop es makes the data segment, additional segment and code segment the same segment.

Mov @ @ digits, 3; Decimal number

mov @@Type_Data,' B '; The type of data saved. B= byte type, W= word type.

; -

; Displays the name, student number and grade title, and prompts for student information.

Output prompt _ string

Call GetCursor to get cursor position.

Mov Temp _ cursor, dx; Cursor position for saving input and displaying student information.

; -

; Enter the student's name, student number and grades.

Lea di, Score _ Table name, student number and grade storage address

Input_Name: call GetCursor to get the cursor position.

mov Buffer_Data,Name _ Length+ 1; Maximum number of characters allowed to be entered

Push di

lea di,Buffer_Data[2]

Mov cx, (name length +2)/2

Mov ax, 2020h fill in the blanks

Represents stosw

Popdi

Lea dx, Buffer _ Data nameEnter the buffer address.

Ah, 0ah

int 2 1h

lea si,Buffer_Data[ 1]

Lodsb reads the number of characters actually entered.

Test aluminum, aluminum

JZ @ @ l 1; If you enter a student's name and enter it directly, it is considered that you have entered the student's name, student number, grades, etc. It's over. It's time to count the number of students entering.

Mov cx, name _ length; Number of characters in the name

Rep movsb writes into the student information buffer.

add Cursor_Col,Name _ Length+2; Add the column number, name length and 2, and start to enter the student number.

Call SetCursor cursor cursor position

Push di

lea di,Buffer_Data[2]

Mov cx, (name length +2)/2

Mov ax, 2020h fill in the blanks

Represents stosw

Popdi

Lea dx, Buffer _ Data Student ID Enter the buffer address.

Ah, 0ah

int 2 1h

lea si,Buffer_Data[2]

Mov cx, ID _ Length student numeric characters

Rep movsb writes into the student information buffer.

add Cursor_Col,ID _ Length+2; Add up the number of columns and the length of the student number, add 2, and start to enter the grades.

Call SetCursor cursor cursor position

Call Input _ Digit to enter the score.

Call Output _ CTLF;; Output carriage return and line feed

Jmp input name; Enter the next student information.

; -

; Calculate the number of students enrolled.

@@L 1: mov ax,di

Subaxis, Offset Fraction _ Table; Memory capacity occupied by all student information

Mov bl, type Info _ Students information memory capacity of each student.

div bl

mov cx,ax; CX= number of students enrolled

Test cx, cx

jnz @@L00

Jmp Exit _ Proc If you don't enter any information, end the program directly.

; -

; Establish a linked list of student information

@@L00: Push di; Save link list address

Lea ax, the starting address of the Score _ Table student information.

Push cx

@ @ L2:stosw; Save student information address

Add ax and type Info _ Students' information memory capacity of each student.

Loop @@L2

Popular cx

Popular si; Pop up the linked list address to si.

cmp cx,2

Jb exit _ process; If you only enter the information of 1 student, you don't need to sort and display the results.

; -

; Sort by bubble sorting in descending order of scores.

Push si; Stacking and saving linked list addresses

Push CX; Save the number of students

Dec cx is ready to sort by bubble sorting.

@ @ Sort: Push CX; Number of external loops saved in the stack.

Push si; Stack save array address

@@Compare: push si

Pop di assigns the address of the current array element to the target index register for exchange.

Lodsw reads the current student information address into AX.

mov bx,ax

mov al,[bx。 score _ Student]; Read the current student's grades into AL.

mov bx,[si]; Next adjacent student information address

cmp al,[bx。 score _ Student]; Compare the performance of the current student with that of the next student.

Jae @ @ NextOne, if greater than or equal to, will process the next array element without exchanging data.

mov ax,[di]; If less than, read the current student information linked list node.

xchg ax,[si]; Link exchange list element

mov [di],ax; Save the node address with a larger value.

@ @ next one:loop @ @ Compare; Process the next array element

Popular si; Array address stack

Out-of-loop stack time of pop cx

Loop @ @ sort; Next comparison

Call output _CTLF

; -

; Displays all student information in descending order of grades.

Output Prompt _ Str to display the title of student information.

Call GetCursor to get cursor position.

Mov Temp _ cursor, dx; Cursor position for saving and displaying student information.

Number of pop cx pop-up students

Popular si; Pop-up list address

Push CX; Save the number of students

xor bx,bx; Total initial value

@ @ List _ Info:push CX; Save the number of students

Call GetCursor to get cursor position.

Lodsw reads into a node of the linked list.

Push si; Stacking and saving linked list addresses

Motion si, ax

Push si; Enter the stack to save the student information address.

Yes, yes. name _ Student]; Name and address

Mov cx, name _ length; Name string length

@ @ Dsip _ Name:lodsb; Read in a character

Cmp al, 0dh return character?

Jz @ @ L3 Yes, the name display is over.

mov dl,al

Call Output _ Chr to display a character.

Loop @ @ Dsip _ Name next character

@@L3: add Cursor_Col,Name _ Length+2; Add 2 to the column number and name length to start displaying the student number.

Call SetCursor cursor cursor position

Popular si; Pop-up student information address

Push si; Enter the stack to save the student information address.

Yes, yes. ID _ Student]; Student number address

Mov cx, ID _ Length name string length

@ @ Dsip _ ID:lodsb; Read in a character

Cmp al, 0dh return character?

Jz @ @ L4 Yes, the display of student number is over.

mov dl,al

Call Output _ Chr to display a character.

Loop @ @ Dsip _ ID next character

@@L4: add Cursor_Col,ID _ Length+2; Add 2 to the length of the column number and student number to start displaying the results.

Call SetCursor cursor cursor position

Popular si; Pop-up student information address

Yes, yes. score _ Student]; result address

Lodsb graded reading

XOR, ah

Plus bx, ax; Cumulative total score

Call Dec _ ASCII to convert the binary unsigned number in AX into an explicit decimal ASCII code, and send it to the display screen for display.

Call output _CTLF

Popular si; Pop-up list address

Number of pop cx pop-up students

Loop @ @ List _ Info Next node (student information)

Call output _CTLF

; -

; Calculate and display the average score

Output prompt _ Ave prompt to display average score.

mov ax,bx

Number of pop bx pop-up students

Div bl bisects the integer part.

Mov bh, ah; Save the rest

XOR, ah

Call Dec _ ASCII to display the average score.

mov ah,BH; remainder

mov bh,bl; divisor

mov cx,2; Reserved decimal places

Call Dec _ Frac to convert the binary unsigned number in AL into decimal explicit decimal ASCII code.

; -

Exit_Proc: output Press _ Key to indicate that the operation is completed, and press any key to end the program.

mov ah, 1

int 2 1h

Mov ah, 4ch ends the program.

int 2 1h

Score _ Form:; Student achievement storage area

End of code

End and start; This is the end of compilation.