Input and save struct in assembly language

Source: Internet
Author: User

Count equ 1

ALL_INPUT macro string, NUM, FUNCTION
Mov dx, OFFSET STRING
Mov ah, 9 H
INT 21 H
Mov di, offset info. & NUM
Mov ax, size info. & NUM
CALL FUNCTION
ENDM


SCORE STRUC
No dw?
Names db 8 DUP (?)
Cscore db 0
Mscore db 0
Escore db 0
SCORE ENDS


DSEG SEGMENT
Info score <12, 'wang ', 12, 23, 21>
S_NO DB 0DH, 0AH, "student no:", '$'
S_NAME DB 0DH, 0AH, "student name:", '$'
S_CSCORE DB 0DH, 0AH, "Chiness score:", '$'
S_MSCORE DB 0DH, 0AH, "Math score:", '$'
S_ESCORE DB 0DH, 0AH, "English score:", '$'
FILE_NAME DB 'data. DAT ', 0
OPEN_ERR DB 0DH, 0AH, "open file error! ", '$'
Buffer db 10 DUP (?)
DSEG ENDS

SSEG SEGMENT PARA STACK
DB 256 DUP (?)
SSEG ENDS

CSEG SEGMENT
Assume ds: DSEG, CS: CSEG, SS: SSEG, ES: DSEG
START: mov ax, DSEG
Mov ds, AX
Mov es, AX
Mov dx, OFFSET FILE_NAME
Mov al, 02 H
Mov ah, 3DH
INT 21 H
JC _ ERROR
Mov bx, AX
Mov cx, COUNT
_ INPUT: NOP
ALL_INPUT S_NO, NO, ASSIC_INPUT
ALL_INPUT S_NAME, NAMES, ASSIC_INPUT
ALL_INPUT S_CSCORE, CSCORE, NUMBER_INPUT
ALL_INPUT S_MSCORE, MSCORE, NUMBER_INPUT
ALL_INPUT S_ESCORE, ESCORE, NUMBER_INPUT
Mov dx, OFFSET INFO
CALL SAVA
LOOP _ INPUT
JMP ENDPROC
_ ERROR: mov dx, OFFSET OPEN_ERR
Mov ah, 9 H
INT 21 H
JMP ENDPROC

SAVA PROC
PUSH CX
Mov cx, SIZE INFO
Mov ah, 40 H
INT 21 H
POP CX
RET
SAVA ENDP

ASSIC_INPUT PROC; address in di, INPUT NUM IN AX
PUSH AX
PUSH CX
PUSH SI
Mov si, OFFSET BUFFER
Mov cx, AX
INPUT_STR: mov ah, 1 H
INT 21 H
Cmp al, 0DH
JZ TRANST_STR
MOV [SI], AL
INC SI
JMP INPUT_STR
TRANST_STR: mov si, OFFSET BUFFER
REP MOVSB
POP SI
POP CX
POP AX
RET
ASSIC_INPUT ENDP

NUMBER_INPUT PROC; address in di, INPUT NUM IN AX
PUSH AX
PUSH CX
PUSH SI
Mov si, OFFSET BUFFER
Mov cx, AX
INPUT_NUM: mov ah, 1 H
INT 21 H
Cmp al, 0DH
JZ TRANST_NUM
Sub al, 30
ADD [SI], AL
JNC NCARRED
CARRED: inc si; IF CARRED
Xor al, AL
INC AL
MOV [SI], AL
NCARRED: JMP INPUT_NUM
TRANST_NUM: mov si, OFFSET BUFFER
REP MOVSB
POP SI
POP CX
POP AX
RET
NUMBER_INPUT ENDP

ENDPROC: mov ah, 3EH
INT 21 H
Mov ah, 4CH
INT 21 H
CSEG ENDS
END START

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.