汇编语言程序题

更新时间:2024-05-18 03:24:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

例1:设内存单元DATA存放一字节无符号数,编程将其拆成两位十六进制数,并存入HEX、HEX+1的低四位。HEX单元存放低位十六进制数,HEX+1单元存放高位十六进制数。 思路:屏蔽,移位 DSEG SEGMENT DATA DB 8AH HEX DB 0,0 DSEG ENDS

sseg segment stack db 100 dup(0) sseg ends CSEG SEGMENT

ASSUME CS:CSEG,DS:DSEG,ss:sseg START:MOV AX,DSEG MOV DS,AX MOV AL,DATA MOV AH,AL

AND AL,0FH

MOV HEX,AL AND AH,0F0H MOV CL,4 SHR AH,CL MOV HEX+1,AH mov ah,4ch int 21h CSEG ENDS

END START

例3:利用查表的方法将1位十六进制数转换成它对应的ASCII码。 思路:查表代替数据运算 DSEG SEGMENT

TABLE DB 30H,31H,32H,33H,34H,35H,36H,37H,38H,39H,41H,42H,43H,44H.45H,46H HEX DB 4 ASCII DB ? DSEG ENDS

sseg segment stack db 100 dup(0) sseg ends CSEG SEGMENT

ASSUME CS:CSEG,DS:DSEG,ss:sseg START:MOV AX,DSEG MOV DS,AX

MOV BX,OFFSET TABLE MOV AL,HEX MOV AH,0

ADD BX,AX MOV AL,[BX] mov ah,4ch int 21h CSEG ENDS END START

?1????????????x?0?例1、 计算 y??0???????????x?0

??1?????????x?0? 设X为单字节带符号整数,且存于DATA1单元,计算结果Y 存于DATA2单元。

开始 AL<- X N X>=0? Y Y AL<- -1 X=0? N AL<- 1 结束

DSEG SEGMENT DATA1 DB 45 DATA2 DB ? DSEG ENDS

sseg segment stack db 100 dup(0) sseg ends CSEG SEGMENT

ASSUME CS:CSEG,DS:DSEG,ss:sseg START: MOV AX,DSEG MOV DS,AX MOV AL,DATA1 CMP AL ,0 JGE BIG MOV AL,0FFH JMP DONE BIG: JE DONE MOV AL,1 DONE:MOV DATA2,AL mov ah,4ch int 21h CSEG ENDS

END START

例2、设内存中有三个互不相等的无符号字数据,分别存放在DATA开始的字单元中,编程将其中最小值存入MIN单元。

参考程序: DSEG SEGMENT

DATA DW 4321H,7658H,9B00H MIN DW ? DSEG ENDS

sseg segment stack db 100 dup(0) sseg ends CSEG SEGMENT

ASSUME CS:CSEG,DS:DSEG,ss:sseg START:MOV AX,DSEG MOV DS,AX LEA SI,DATA MOV AX,[SI] MOV BX,[SI+2] CMP AX,BX JC NEXT MOV AX,BX NEXT:CMP AX,[SI+4] JC DONE

MOV AX,[SI+4] DONE:MOV MIN,AX mov ah,4ch int 21h CSEG ENDS

END START

试编程,统计由DATA单元开始的数据块中负数的个数。结果存于COUNT单元中 设数据定义如下:(10分) DSEG SEGMENT

DATA DB –1,0,23,-78,32,0AH DB 0FFH,87H,34,23H COUNT DW ? DSEG ENDS

DSEG SEGMENT

DATA DB –1,0,23,-78,32,0AH DB 0FFH,87H,34,23H COUNT DW ? DSEG ENDS

SSEG SEGMENT STACK STK DB 100 DUP (?) SSEG ENDS CSEG SEGMENT

ASSUME DS:DSEG,SS:SSEG,CS:CSEG START: MOV AX,DSEG MOV DS,AX LEA BX,DATA MOV CX,10 MOV DX,0

LP: MOV AL,[BX] AND AL,AL JNS NEXT INC DX

NEXT: INC BX LOOP LP

MOV COUNT,DX MOV AH,4CH INT 21H CSEG ENDS END START

例2:试编程,统计由DATA单元开始的数据块中能被3整除的数的个数。结果存于COUNT单元中。(设数据块中共有10个无符号数) 设数据定义如下:(10分) DSEG SEGMENT

DATA DB 41,9,33H,0F0H,32,0AH DB 0FFH,99,68,23H

COUNT DW ? DSEG ENDS

DSEG SEGMENT

DATA DB 41,9,33H,0F0H,32,0AH DB 0FFH,99,68,23H COUNT DW ? DSEG ENDS

SSEG SEGMENT STACK STK DB 100 DUP (?) SSEG ENDS CSEG SEGMENT

ASSUME DS:DSEG,SS:SSEG,CS:CSEG START: MOV AX,DSEG MOV DS,AX LEA SI,DATA MOV CX,10 MOV DX,0 MOV BL,3

LP: MOV AL,[SI] MOV AH,0 DIV BL AND AH,AH JNZ NEXT INC DX

NEXT: INC SI LOOP LP

MOV COUNT,DX MOV AH,4CH INT 21H CSEG ENDS END START

例4:在一组字符串中寻找’AM’的出现次数,该串放在PROG起,并以ctrl+Z(1AH)结束,统计结果送入字变量NUM中。

DSEG SEGMENT

PROG db 'I AM Amp SAAS ASLKSA AMSDSAASMMASSAM',1AH NUM DW 0 DSEG ENDS

sseg segment stack

本文来源:https://www.bwwdw.com/article/j7e7.html

Top