我是新手,求高手帮忙!编写一个汇编语言程序;

2024-12-24 11:51:44
推荐回答(2个)
回答1:

data segment
str db 10
db "fgdsgfgj",0dh,0ah,0
num db 5
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov al,num
cmp al,[str]
ja exit
mov al,[str]
sub al,num
mov cl,al
mov ch,0
mov BX,offset str
rot: add bx,1 ;//字符串从str+1开始
add bx,str //指向串的最后一个单元
mov al,[bx-1]
mov [bx],al ;字符串后移
loop rot
exit: mov ax,4c00h
int 21h
code ends
end start

回答2:

下列程序,可满足题目要求:

DATA SEGMENT
STR DB 18
DB "ABCDEFGHIJKLMNOPQZ"
NUM DB 5
DATA ENDS
;-----------------------------
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX, DATA
MOV DS, AX
;-------------------
MOV AL, NUM
CMP AL, STR
JA EXIT
;-------------------
MOV BX, OFFSET STR
MOV AL, NUM
MOV AH, 0
ADD BX, AX
INC BX
MOV AH, [BX]
MOV BYTE PTR [BX], '?'
MOV AL, STR
SUB AL, NUM
MOV CL, AL
MOV CH, 0
ROT:
INC BX
XCHG AH, [BX]
LOOP ROT
EXIT:
MOV AX, 4C00H
INT 21H
CODE ENDS
;-----------------------------
END START