本文目录一览:
汇编语言小题一个,感激不尽
;如果在dos下编译,将中文注释删除后进行。
data segment
str1 db 'abcdefghijklmn........',0h,'other string, useless'
str2 db 'def',0h,'other string'
len1 dw 0
len2 dw 0
lastpos dw 0
msg0 db 'found it, position at :','$'
msg1 db 'not found.$'
pos dw 0
found db 0
data ends
assume cs:code, ds:data, es:data
code segment
start:
mov ax, data
mov ds, ax
mov es, ax
;计算str1长度
lea si, str1,
lea di, len1
call strlen
;计算str2长度
lea si, str2,
lea di, len2
call strlen
;计算str1最大可查找position
mov ax, offset str1
mov bx, ax ;bx保存查找起始位置
add ax, len1
sub ax, len2
inc ax
mov lastpos, ax ;当查找从这里开始时,就表示不可能匹配上了,因为剩余字符串长度不够
;开始查找
cld ;设置查找方向为增向
search0:
mov cx, len2
mov si, bx
lea di, str2
repe cmpsb
jz found0 ;zf为0,表示找到
inc bx
cmp bx, lastpos
jnz search0
;执行到这里,表示未找到
lea dx, msg1
mov ah, 9
int 21h
jmp exit
found0:
mov found, 0ffh ;把这2个要求忘掉了。
mov pos bx ;
;输出(bx),即在str1中的首地址
lea dx, msg0
mov ah, 9
int 21h
mov ax, bx
call print
exit:
mov ax, 4c00h
int 21h
;计算[si]指向的字符串的长度
;0为字符串结束符号
;[di]保存计算结果,dw类型
strlen proc near
mov [di], 0
strlen0:
cmp [si], 0
jz strlen1
inc [di]
inc si
jmp strlen0
strlen1:
ret
strlen endp
;10进制输出(ax)中的数值
print proc near
push cx
push bx
xor cx, cx
mov bx, 10
p0:
xor dx, dx
div bx
xor dx, 0e30h
push dx
inc cx
cmp ax, 0
jnz p0
p1:
pop ax
int 10h
loop p1
pop bx
pop cx
ret
print endp
code ends
end start
电脑单机游戏拳皇下载百度云资源分享给我
《小七单机GM视频教程》百度网盘资源免费下载
链接:
提取码:jh2a
小七单机GM视频教程|小七单机游戏GM教程.mp4|同时玩多个版本教程等2个文件.zip|同时玩多个版本教程.mp4|假人攻城演示.mp4
用汇编语言编写10个任意数相加求和的乘坐
用汇编语言编写10个任意数相加求和的程序:
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
START: PUSH CS
POP DS
PUSH CS
POP ES
CALL INPUTNUM
MOV AH,2
MOV DL,13
INT 21H
MOV DL,10
INT 21H
LEA SI,@ARRAY
MOV CX,@NUM
CLD
@1:
LODSW
add word ptr sum,ax
CALL DISPAXS
LOOP @1
MOV AH,2
MOV DL,13
INT 21H
MOV DL,10
INT 21H
mov ax,sum
call dispaxs
MOV AH,4CH
INT 21H
sum dw 0
;===============================================
; 键盘输入数值数组子程序(数组名为@array,元素个数存放在@num中)
; 可以是负数
INPUTNUM PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSHF
; 对数组@array清零
MOV CX,100
MOV AX,0
LEA DI,@ARRAY
REP STOSW
MOV WORD PTR @NUM,0
; 输入的数据以一个空格分隔,以回车符结束输入
LEA DX,@STRA
MOV AH,10
INT 21H
MOV CL,@STRN
MOV CH,0
MOV WORD PTR @STRM,CX
LEA SI,@STR
CLD
LEA DI,@ARRAY
MOV WORD PTR @NUM,0
@STIN:
MOV AX,0
PUSH AX
MOV BYTE PTR @SIGNN,0
@AGAIN1:
;MOV AH,1
;INT 21H
CMP WORD PTR @STRM,0
JE @LINE0
LODSB
DEC WORD PTR @STRM
; MOV BYTE PTR @CHAR,AL
; CMP AL,13
; JE @LINE0
CMP AL,' '
JE @LINE0
CMP AL,'-'
JNE @INPUT1
MOV BYTE PTR @SIGNN,1
JMP @AGAIN1
@INPUT1:
SUB AL,30H
MOV AH,0
MOV BX,AX
POP AX
MOV CL,10
MOV CH,0
MUL CX
ADD AX,BX
PUSH AX
JMP @AGAIN1
@LINE0:
POP AX
CMP BYTE PTR @SIGNN,1
JNE @INPUT2
NEG AX
@INPUT2:
MOV WORD PTR[DI],AX
INC WORD PTR @NUM
; CMP BYTE PTR @CHAR,13
CMP WORD PTR @STRM,0
JE @STINEND
INC DI
INC DI
JMP @STIN
@STINEND:
POPF
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
@STRA DB 255
@STRN DB ?
@STR DB 255 DUP(?)
@STRM DW 0
@ARRAY DW 100 DUP(0)
@NUM DW 0
@CHAR DB ?
@SIGNN DB 0
INPUTNUM ENDP
;=========================================
; 将要显示的有符号数置于 ax 中
DISPAXS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSH DS
PUSH ES
PUSHF
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,6
LEA DI,DISPAXSS
@DISPAXS:
MOV BYTE PTR [DI],32
INC DI
LOOP @DISPAXS
PUSH AX
MOV DL,32
MOV AH,2
INT 21H
POP AX
MOV BYTE PTR NZS,0
MOV BYTE PTR SIGNS,0
CMP AX,0
JGE @DISPAXS0
MOV BYTE PTR SIGNS,1
NEG AX
@DISPAXS0:
PUSH AX
LEA SI,DIVARRS
LEA DI,DISPAXSS
INC DI
MOV CX,5
@DISPAXS1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @DISPAXS2
CMP BYTE PTR NZS,1
JE @DISPAXS2
CMP CX,1
JE @DISPAXS2
MOV DL,20H
JMP @DISPAXS3
@DISPAXS2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZS,1
@DISPAXS3:
MOV BYTE PTR[DI],DL
INC SI
INC SI
INC DI
LOOP @DISPAXS1
POP DX
CMP BYTE PTR SIGNS,1
JNE @DISPAXS6
LEA SI,DISPAXSS
ADD SI,5
@DISPAXS4:
CMP BYTE PTR [SI],32
JE @DISPAXS5
DEC SI
JMP @DISPAXS4
@DISPAXS5:
MOV BYTE PTR [SI],'-'
@DISPAXS6:
LEA DX,DISPAXSS
MOV AH,9
INT 21H
POPF
POP ES
POP DS
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARRS DW 10000,1000,100,10,1
NZS DB 0
SIGNS DB 0
DISPAXSS DB 32,32,32,32,32,32,'$'
DISPAXS ENDP
;==================================
CODE ENDS
END START
汇编语言程序,有符号数排序
CODE SEGMENT
ASSUME CS:CODE
ORG 100H
START: JMP BEGIN
ARR1 DB 3AH,80H,0BH,55H,0FFH
NUM EQU $-ARR1
BEGIN: PUSH CS
POP DS
PUSH CS
POP ES
LEA SI,ARR1
MOV CX,NUM
CALL SORTBYTE
LEA SI,ARR1
MOV CX,NUM
@0:
LODSB
CBW
CALL DISPAXS
LOOP @0
MOV AH,4CH
INT 21H
;===============================================
; 字节数组排序(有符号数冒泡排序)
SORTBYTE PROC NEAR
; 数组长度置入cx,数组首地址置入 si
PUSH AX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSHF
PUSH CX
POP DX
DEC DX
@SORTBL1:
MOV CX,DX
MOV DI,SI
@SORTBL2:
MOV AL,[DI+1]
CMP AL,[DI]
JL @SORTBNEXT ; 从大到小(无符号换成 JB)
XCHG AL,[DI]
MOV [DI+1],AL
@SORTBNEXT:
INC DI
LOOP @SORTBL2
DEC DX
JNZ @SORTBL1
POPF
POP DI
POP SI
POP DX
POP CX
POP AX
RET
SORTBYTE ENDP
;===============================================
; 将要显示的有符号数置于 ax 中
DISPAXS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSH DS
PUSH ES
PUSHF
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,6
LEA DI,DISPAXSS
@DISPAXS:
MOV BYTE PTR [DI],32
INC DI
LOOP @DISPAXS
PUSH AX
MOV DL,32
MOV AH,2
INT 21H
POP AX
MOV BYTE PTR NZS,0
MOV BYTE PTR SIGNS,0
CMP AX,0
JGE @DISPAXS0
MOV BYTE PTR SIGNS,1
NEG AX
@DISPAXS0:
PUSH AX
LEA SI,DIVARRS
LEA DI,DISPAXSS
INC DI
MOV CX,5
@DISPAXS1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @DISPAXS2
CMP BYTE PTR NZS,1
JE @DISPAXS2
CMP CX,1
JE @DISPAXS2
MOV DL,20H
JMP @DISPAXS3
@DISPAXS2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZS,1
@DISPAXS3:
MOV BYTE PTR[DI],DL
INC SI
INC SI
INC DI
LOOP @DISPAXS1
POP DX
CMP BYTE PTR SIGNS,1
JNE @DISPAXS6
LEA SI,DISPAXSS
ADD SI,5
@DISPAXS4:
CMP BYTE PTR [SI],32
JE @DISPAXS5
DEC SI
JMP @DISPAXS4
@DISPAXS5:
MOV BYTE PTR [SI],'-'
@DISPAXS6:
LEA DX,DISPAXSS
MOV AH,9
INT 21H
POPF
POP ES
POP DS
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARRS DW 10000,1000,100,10,1
NZS DB 0
SIGNS DB 0
DISPAXSS DB 32,32,32,32,32,32,'$'
DISPAXS ENDP
;==================================
CODE ENDS
END START
如何使用汇编语言实现冒泡排序
内存以BUF单元开始有若干单字节有符号数,编程实现从大到小排序并以十进制输出。
code segment
assume cs:code
org 100h
start:jmp begin
buf db 3,4,5,0,-1,-2,-3
n dw $-buf
begin:push cs
pop ds
push cs
pop es
lea si,buf
mov cx,n
call sort
mov cx,n
lea si,buf
@1:
lodsb
cbw
call dispaxs
loop @1
mov ah,4ch
int 21h
;=============================================
; 字节数组排序(冒泡排序)
sort proc near
; 数组元素个数置入cx,首地址置入 si
push ax
push cx
push dx
push si
push di
pushf
push cx
pop dx
dec dx
@sortl1:
mov cx,dx
mov di,si
@sortl2:
mov al,[di+1]
cmp al,[di]
jl @sortnext ; 无符号数排序改为 jb
xchg al,[di]
mov [di+1],al
@sortnext:
inc di
loop @sortl2
dec dx
jnz @sortl1
popf
pop di
pop si
pop dx
pop cx
pop ax
ret
sort endp
;====================================================
; 将要显示的有符号数置于 ax 中
DISPAXS PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH BP
PUSH DS
PUSH ES
PUSHF
PUSH CS
POP DS
PUSH CS
POP ES
MOV CX,6
LEA DI,DISPAXSS
@DISPAXS:
MOV BYTE PTR [DI],32
INC DI
LOOP @DISPAXS
PUSH AX
MOV DL,32
MOV AH,2
INT 21H
POP AX
MOV BYTE PTR NZS,0
MOV BYTE PTR SIGNS,0
CMP AX,0
JGE @DISPAXS0
MOV BYTE PTR SIGNS,1
NEG AX
@DISPAXS0:
PUSH AX
LEA SI,DIVARRS
LEA DI,DISPAXSS
INC DI
MOV CX,5
@DISPAXS1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @DISPAXS2
CMP BYTE PTR NZS,1
JE @DISPAXS2
CMP CX,1
JE @DISPAXS2
MOV DL,20H
JMP @DISPAXS3
@DISPAXS2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZS,1
@DISPAXS3:
MOV BYTE PTR[DI],DL
INC SI
INC SI
INC DI
LOOP @DISPAXS1
POP DX
CMP BYTE PTR SIGNS,1
JNE @DISPAXS6
LEA SI,DISPAXSS
ADD SI,5
@DISPAXS4:
CMP BYTE PTR [SI],32
JE @DISPAXS5
DEC SI
JMP @DISPAXS4
@DISPAXS5:
MOV BYTE PTR [SI],'-'
@DISPAXS6:
LEA DX,DISPAXSS
MOV AH,9
INT 21H
POPF
POP ES
POP DS
POP BP
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
RET
DIVARRS DW 10000,1000,100,10,1
NZS DB 0
SIGNS DB 0
DISPAXSS DB 32,32,32,32,32,32,'$'
DISPAXS ENDP
;================================================
code ends
end start