用組合語言實現結構體的輸入和儲存

來源:互聯網
上載者:User

COUNT EQU 1

ALL_INPUT MACRO  STRING,NUM,FUNCTION  
MOV DX,OFFSET STRING
MOV AH,9H
INT 21H
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,02H
            MOV AH,3DH
            INT 21H
   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,9H
   INT 21H
   JMP ENDPROC
   
   SAVA PROC
   PUSH CX
   MOV CX,SIZE INFO
   MOV AH,40H
   INT 21H
   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,1H
            INT 21H
            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,1H
            INT 21H
            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 21H
            MOV AH,4CH
   INT 21H
CSEG ENDS
END START

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.