汇编练习

匿名 (未验证) 提交于 2019-12-03 00:22:01

练习一:统计复数的个数

DTSEG SEGMENT   MES1  DB    'The result is:$'   NUMB  DB 12H,88H,82H,89H,33H,90H,01H,10H,0BDH,01H   DTSEG ENDS      CDSEG SEGMENT         ASSUME CS:CDSEG,DS:DTSEG   START:MOV AX,DTSEG         MOV DS,AX                  MOV   DX,OFFSET MES1         MOV   AH,09H         INT   21H         MOV BL,0H         MOV CX,0AH         MOV SI,OFFSET NUMB   NEXT: MOV AX,[SI]         AND AX,80H  ;判断是否是负数       CMP AX,0H         JG  MIN         JMP CON   MIN:  INC BL   CON:  INC SI         LOOP NEXT         CALL SHOW          MOV AH,4CH         INT 21H                 SHOW    PROC    NEAR          PUSH AX          PUSH DX          MOV  AL,BL          AND  AL,0F0H         ;取高4位          SHR  AL,4          CMP  AL,0AH          ;是否是A以上的数          JB   C2                ADD  AL,07H         C2:    ADD  AL,30H                MOV  DL,AL           ;show character           MOV  AH,02H          INT  21H          MOV  AL,BL          AND  AL,0FH          ;取低4位          CMP  AL,0AH          JB   C3          ADD  AL,07H   C3:    ADD  AL,30H          MOV  DL,AL           ;show character           MOV  AH,02H          INT  21H          POP  DX          POP  AX          RET          ENDP    CDSEG ENDS         END START  

联系2:找出最大最小值

; You may customize this and other start-up templates;  ; The location of this template is c:\emu8086\inc\0_com_template.txt   STACK1  SEGMENT STACK            DW 256 DUP(?)   STACK1  ENDS      DDATA   SEGMENT   MES1    DB 'The least number is:$'   MES2    DB 0AH,0DH,'The largest number is:$'   NUMB    DB 0D9H,07H,8BH,0C5H,0EBH,04H,9DH,0F9H   DDATA   ENDS      CODE SEGMENT       ASSUME CS:CODE,DS:DDATA          START: MOV  AX,DDATA          MOV  DS,AX             MOV  SI,OFFSET NUMB          MOV  CX,0008H          ;JCXZ A4          MOV  BH,[SI]          MOV  BL,BH  ;BL记录最小值,BH记录最大值 A1:    LODSB            ;AL=DS:[SI],SI=SI+1 取串指令          CMP  AL,BH          JBE  A2          MOV  BH,AL          JMP  A3   A2:    CMP  AL,BL          JAE  A3          MOV  BL,AL   A3:    LOOP A1      A4:    MOV  DX,OFFSET MES1  ;show mes1          MOV  AH,09H                INT  21H              MOV  AL,BL       ;show the least number          AND  AL,0F0H     ;get the highest 4 bits          SHR  AL,4          CMP  AL,0AH                JB   C2                ADD  AL,07H         C2:    ADD  AL,30H                MOV  DL,AL       ;show character           MOV  AH,02H          INT  21H          MOV  AL,BL          AND  AL,0FH      ;get the lowest 4 bits          CMP  AL,0AH          JB   C3          ADD  AL,07H   C3:    ADD  AL,30H          MOV  DL,AL       ;show character           MOV  AH,02H          INT  21H             MOV  DX,OFFSET MES2  ;show mes2          MOV  AH,09H                INT  21H              MOV  AL,BH       ;show the largest number          AND  AL,0F0H     ;get the highest 4 bits          SHR  AL,4          CMP  AL,0AH                JB   C22               ADD  AL,07H         C22:   ADD  AL,30H                MOV  DL,AL       ;show character           MOV  AH,02H          INT  21H          MOV  AL,BH          AND  AL,0FH      ;get the lowest 4 bits          CMP  AL,0AH          JB   C33          ADD  AL,07H   C33:   ADD  AL,30H          MOV  DL,AL       ;show character           MOV  AH,02H          INT  21H             MOV  AX,4C00H    ;go back to dos          INT  21H   CODE ENDS          END START  

练习3:双精度加法计算

要求计算X+Y=Z,将结果Z输出到屏幕上,其中X=001565A0H,Y=0021B79EH。实验利用累加器AX,先求低十六位和,并存入地址存储单元,后求高16位和,再存入高址存储单元。由于地位可能向高位有进位,因而高位相加语句需用ADC指令,则地位相加有进位时,CF=1,高位字相加时,同时加上CF中的1。在80386以上微机中可以直接使用32位寄存器和32位加法指令完成。   ;二进制双精度加法运算      STACK1  SEGMENT STACK            DW 256 DUP(?)   STACK1  ENDS      DATA SEGMENT   MES1    DB  'The result is:$'   XL      DW  65A0H   XH  DW  0015H   YL  DW  0B79EH   YH  DW  0021H   DATA    ENDS      CODE SEGMENT          ASSUME CS:CODE,DS:DATA   START: MOV  AX,DATA          MOV  DS,AX             MOV  DX,OFFSET MES1  ;将MES1偏移地址给DX          MOV  AH,09H      ;将MES1中的内容输出到屏幕          INT  21H          MOV  AX,XL          ADD  AX,YL          MOV  BX,AX          MOV  AX,XH          ADC  AX,YH          PUSH BX           ;入栈保存BX          CALL SHWORD          ;先去执行SHWORD          POP  BX              ;返回继续执行BX出栈处理          MOV  AX,BX           ;此时AX中是低16位之和          CALL SHWORD          ;再次调用SHWORD             MOV  AX,4C00H          INT  21H      SHWORD  PROC    NEAR          MOV  BL,AH           ;保持高16位的高8位          CALL SHOW            ;显示结果          MOV  BL,AL           ;保持高16位的低8位          CALL SHOW            ;显示结果          RET            ENDP              SHOW    PROC    NEAR          PUSH AX              ;保持AX          PUSH DX              ;保存DX          MOV  AL,BL          AND  AL,0F0H         ;AL与0F0H相与取高4位          SHR  AL,4          CMP  AL,0AH          ;是否是A以上的数          JB   C2                ADD  AL,07H                  ;A以上的数加07H折显示的是字母      C2:    ADD  AL,30H                MOV  DL,AL           ;show character           MOV  AH,02H          INT  21H          MOV  AL,BL          AND  AL,0FH          ;AL与0FH相与取低4位          CMP  AL,0AH          JB   C3          ADD  AL,07H   C3:    ADD  AL,30H          MOV  DL,AL           ;show character           MOV  AH,02H          INT  21H          POP  DX          POP  AX          RET          ENDP    CODE ENDS          END START  

文章来源: 汇编练习
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!