1.用8086汇编语言编程
;X86汇编_求0-9立方,显示结果
; MASM5.0编译后,运行无误
code segment
assume cs:code,ds:code
org 100h
start:
push cs
pop ds
Again:lea dx,Tips1
mov ah,9
int 21h ;显示提示
@In:mov ah,0
int 16h ;无回显输入
cmp al,1bh ;Esc退出程序
jz quit
cmp al,'0'
jb @Err
cmp al,'9';数据校验
jbe Q2
@Err:
mov ah,0eh
int 10h
lea dx,Err
jmp Q3
Q2:
mov X,al
sub al,'0'
mov dl,al
mul al
mul dl
lea si,Y
lea di,Z
mov cx,3
Q4:xor dx,dx
div word ptr [di]
or al,'0'
mov [si],al
inc si
inc di
inc di
mov ax,dx
loop Q4
lea dx,Result
Q3:
mov ah,9
int 21h
jmp Again
quit:
mov ah,4ch
int 21h
Err db 0dh,0ah,'INPUT ERROR!$'
Tips1 db 0dh,0ah,'Input(0-9),Esc to Quit: $'
Result db ' '
X db '0^3='
Y db '000$'
z dw 100,10,1
code ends
end start
2.8086汇编语言
DATAS SEGMENT
SJA DB 1,3,5,1,2
SJB DB 2,4,6,2,3
SJC DB 20,40,60,20,10
SJD DB 4,5,6,4,5
SJE DB 5,20,20,20,15
BUF1 DB 10 DUP(' ')
BUF2 DB 10 DUP(' ')
DATAS ENDS
STACKS SEGMENT
DW 10 DUP(0)
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
MOV BX,0
LEA SI,BUF1
LEA DI,BUF2
MOV CX,5
A3: MOV DL,SJA[BX]
MOV AL,SJB[BX]
MUL DL
MOV BP,AX
MOV DL,SJD[BX]
MOV AL,SJC[BX]
CBW
DIV DL
MOV DX,BP
ADD DL,AL
ADC DH,0
SUB DL,SJE[BX]
SBB DH,0
CMP DX,0
JL A1
MOV [SI],DX
JMP A2
A1: MOV [DI],DX
A2: ADD SI,2
ADD DI,2
INC BX
DEC CX
JNZ A3
LEA SI,BUF1
MOV BP,10
A11:MOV AL,[SI+1]
CMP AL,' '
JE A13
MOV BL,AL
MOV CL,4
SHR AL,CL
AND BL,0FH
CMP AL,9
JA A31
ADD AL,30H
JMP A4
A31:ADD AL,37H
A4: MOV DL,AL
MOV AH,2
INT 21H
CMP BL,9
JA A5
ADD BL,30H
JMP A6
A5: ADD BL,37H
A6: MOV DL,BL
MOV AH,2
INT 21H
MOV AL,[SI]
MOV BL,AL
MOV CL,4
SHR AL,CL
AND BL,0FH
CMP AL,9
JA A7
ADD AL,30H
JMP A8
A7: ADD AL,37H
A8: MOV DL,AL
MOV AH,2
INT 21H
CMP BL,9
JA A9
ADD BL,30H
JMP A0
A9: ADD BL,37H
A0: MOV DL,BL
MOV AH,2
INT 21H
MOV DL,' '
MOV AH,2
INT 21H
A13:MOV CX,5
A14:MOV DL,' '
MOV AH,2
INT 21H
LOOP A14
A12:ADD SI,2
DEC BP
JNZ A11
MOV AH,4CH
INT 21H
CODES ENDS
END START
程序很长就不具体解释了,功能区都隔行了的,BUF1和BUF2之间会显示一串空格来分隔。
3.用8086汇编语言编写程序,实现如下功能:通过键盘输入10个学生成
DATA SEGMENT
BLZ1 DB 50 DUP (0)
BLZ2 DB 40,?,60 DUP (0),'$'
MESSAGE DB "Please Input:",'$'
HU DB 0DH,0AH,'$'
DATA ENDS
DUI SEGMENT STACK
DB 100 (0)
DUI ENDS
CODE SEGMENT
ASSUME CS:code,DS:data,SS:DUI
START:
MOV AX,DATA
MOV DS,AX
MOV AX,DUI
MOV SS,AX
XOR AX,AX
MOV DX,OFFSET MESSAGE
MOV AH,9
INT 21H
MOV DX,OFFSET BLZ2
MOV AH,10
INT 21H
MOV SI,OFFSET BLZ2+2
MOV DI,OFFSET BLZ1
MOV CH,10
CHANGE0:
MOV BL,[SI]
SUB BL,30h
MOV CL,4
SHL BL,CL
MOV [DI],BL
INC SI
MOV BL,[SI]
SUB BL,30h
ADD [DI],BL
ADD SI,2
INC DI
DEC CH
JNZ CHANGE0
MOV DX,0
MOV CX,9
MOV DI,offset BLZ1
MOV bx,0
AGAIN : MOV DL,BLZ1[bx]
MOV SI,BX
LOOP0: CMP DL,BLZ1[si]
JA LOOP1
XCHG DL,BLZ1[si]
MOV BLZ1[bx],dl
LOOP1: INC SI
CMP SI,10
JNZ LOOP0
LOOP2:
INC BX
CMP bx,10
JNZ AGAIN
MOV DX,OFFSET HU
MOV AH,9
INT 21H
XOR DX,DX
MOV DI,OFFSET BLZ1
OUT0 : MOV DL,[DI]
MOV DH,0
PUSH DX
MOV CL,4
SHR DL,CL
ADD DL,30h
MOV AH,2
INT 21h
POP DX
AND DL,0fh
ADD DL,30h
MOV AH,2
INT 21h
MOV DL,20h
MOV AH,2
INT 21h
INC DI
DEC BX
JNZ OUT0
MOV AH,4CH
INT 21H
CODE ENDS
END START
4.8086汇编需要的程序(自己随意编写,不用复杂,满足要求就可以)
打印乘法口诀表
PRINT MACRO X
LEA DX,X
MOV AH,9
INT 21H
ENDM
STACKS SEGMENT STACK
DW 128 DUP(?)
STACKS ENDS
DATAS SEGMENT
MSG DB '* ************************ 99 list ******************************',13,10,'*',13,10,'*',20H,'$'
ED DB '***************************************************************','$'
ENTR DB 13,10,'*',20H,13,10,'*',20H,'$'
DATAS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS
START: MOV AX,DATAS
MOV DS,AX
PRINT MSG
MOV CX,9
MOV BH,1 ;HANG
MOV BL,1 ;LIE
NEXT:
MOV DL,BL
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,'x'
MOV AH,2
INT 21H
MOV DL,BH
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,'='
MOV AH,2
INT 21H
MOV AH,0
MOV AL,BL
MUL BH
MOV DL,10
DIV DL
MOV DH,AH
MOV DL,AL
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,DH
ADD DL,30H
MOV AH,2
INT 21H
MOV DL,20H
MOV AH,2
INT 21H
ADD BL,1
CMP BL,BH
JBE NEXT
PRINT ENTR
ADD BH,1
MOV BL,1
LOOP NEXT
EXIT:
PRINT ENTR
PRINT ED
MOV AX,4C00H
INT 21H
CODES ENDS
END START
5.微机
code segment
assume cs:code
org 100h
start: jmp begin
array db 100 dup(?)
sum db 0
begin: push cs
pop ds
push cs
pop es
lea si,array
mov cx,100
cld
@0:
lodsb
add byte ptr sum,al
loop @0
int 3
mov ah,4ch
int 21h
code ends
end start
6.8086汇编语言
DATAS SEGMENT SJA DB 1,3,5,1,2 SJB DB 2,4,6,2,3 SJC DB 20,40,60,20,10 SJD DB 4,5,6,4,5 SJE DB 5,20,20,20,15 BUF1 DB 10 DUP(' ') BUF2 DB 10 DUP(' ')DATAS ENDSSTACKS SEGMENT DW 10 DUP(0)STACKS ENDSCODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKSSTART: MOV AX,DATAS MOV DS,AX MOV BX,0 LEA SI,BUF1 LEA DI,BUF2 MOV CX,5A3: MOV DL,SJA[BX] MOV AL,SJB[BX] MUL DL MOV BP,AX MOV DL,SJD[BX] MOV AL,SJC[BX] CBW DIV DL MOV DX,BP ADD DL,AL ADC DH,0 SUB DL,SJE[BX] SBB DH,0 CMP DX,0 JL A1 MOV [SI],DX JMP A2A1: MOV [DI],DX A2: ADD SI,2 ADD DI,2 INC BX DEC CX JNZ A3 LEA SI,BUF1 MOV BP,10A11:MOV AL,[SI+1] CMP AL,' ' JE A13 MOV BL,AL MOV CL,4 SHR AL,CL AND BL,0FH CMP AL,9 JA A31 ADD AL,30H JMP A4A31:ADD AL,37HA4: MOV DL,AL MOV AH,2 INT 21H CMP BL,9 JA A5 ADD BL,30H JMP A6A5: ADD BL,37HA6: MOV DL,BL MOV AH,2 INT 21H MOV AL,[SI] MOV BL,AL MOV CL,4 SHR AL,CL AND BL,0FH CMP AL,9 JA A7 ADD AL,30H JMP A8A7: ADD AL,37HA8: MOV DL,AL MOV AH,2 INT 21H CMP BL,9 JA A9 ADD BL,30H JMP A0A9: ADD BL,37HA0: MOV DL,BL MOV AH,2 INT 21H MOV DL,' ' MOV AH,2 INT 21HA13:MOV CX,5A14:MOV DL,' ' MOV AH,2 INT 21H LOOP A14 A12:ADD SI,2 DEC BP JNZ A11 MOV AH,4CH INT 21HCODES ENDS END START程序很长就不具体解释了,功能区都隔行了的,BUF1和BUF2之间会显示一串空格来分隔。
7.如何用汇编语言(8086)实现这2个简单程序
1。 在内存BUFF单元中定义有10个16位数,试寻找其中的最大、最小值并分别放到指定的单元MAX和MIN中。
SSEG SEGMENT STACK
STK DB 20 DUP(?)
SSEG ENDS
DSEG SEGMENT
BUFF DW -5,56,45,-96,5,2,457,8,7,-8
MAX DW ?
MIN DW ?
DSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG,DS:DSEG,SS:SSEG
START: MOV AX,DSEG
MOV DS,AX
LEA BX,BUFF
MOV CX,10
MOV AX,[BX]
MOV MIN,AX
MOV MAX,AX
INC BX
DEC CX
AGAIN: MOV AX,[BX]
CMP AX,MIN
JE NEXT
JA A1
MOV MIN,AX
JMP NEXT
A1: CMP AX,MAX
JB NEXT
MOV MAX,AX
NEXT: INC BX
DEC CX
JNZ AGAIN
MOV AH,4CH
INT 21H
CSEG ENDS
END START
2。在BUFF开始的存储区中存放30个带符号数,试统计起正数、负数、零的个数,并将个数分别放到A1、A2、A3单元中。
SSEG SEGMENT STACK
STK DB 20 DUP(?)
SSEG ENDS
DSEG SEGMENT
BUFF DB ………………;省略掉
A1 DB ? ;正数
A2 DB ? ;负数
A3 DB ? ;零;
DSEG ENDS
CSEG SEGMENT
ASSUME CS:CSEG,DS:DSEG,SS:SSEG
START: MOV AX,DSEG
MOV DS,AX
LEA BX,BUFF
MOV DI,30
MOV CX,0
MOV DL,0
L1: MOV AL,[BX]
CMP AL,0
JE L2
JG L3
INC CL
JMP NEXT
L2: INC DL
JMP NEXT
L3: INC CH
NEXT: INC BX
DEC DI
JNZ L1
MOV A1,CH
MOV A2,CL
MOV A3,DL
MOV AH,4CH
INT 21H
CSEG ENDS
END START
转载请注明出处windows之家 » win10如何编写8086汇编程序