计算机原理与汇编实验报告
学号:0909102518
姓名:赵书剑
班级:计科 1005
指导老师:雷向东
完成日期:2012 年 12 月 23 日
目录
计算机原理与汇编实验报告 .............................................................................................................. 1
实验一 冒泡排序................................................................................................................................ 2
一﹑实验目的 ...................................................................................................................... 2
二﹑实验内容 ...................................................................................................................... 3
三、源程序 .......................................................................................................................... 3
四、实验运行结果 ............................................................................................................ 12
实验二 阶乘运算实验...................................................................................................................... 13
一、实验目的 .................................................................................................................. 13
二、实验内容 .................................................................................................................... 13
三、源程序 ........................................................................................................................ 13
四、实验运行结果 ............................................................................................................ 17
实验三 模型机实验 .......................................................................................................................... 17
一、实验目的 .................................................................................................................... 17
二、实验内容 .................................................................................................................... 17
三、实验运行结果 ............................................................................................................ 18
实验一 冒泡排序
一﹑实验目的
1.通过分析、设计、编码、调试等各环节的训练,深刻理解、牢固掌握汇编语言程序设计
技术,掌握分析、解决实际问题的能力。
2.对所给出的问题进行具体的分析,对要完成的任务作出明确的回答。
3.设计中要求综合运用所学知识,上机解决一些适合于汇编语言处理的相关问题
4.熟悉源程序的输入和代码的调试。
二﹑实验内容
使用汇编语言,将 10 个有符号十进制整数,通过冒泡排序法进行排序后,将
排序好的 10 个有符号十进制整数输出,显示在屏幕上。
三、源程序
datarea segment
dw
100 dup(?)
=
10
db
0
db
'Please input ten decimal integers and use the comma as
buf
count
flag
mess1
separation:$'
mess2
mess3
db
db
'error!$'
'The result is: $'
datarea ends
;----------------------------------------
prognam segment
assume cs:prognam,ds:datarea
start:
push
ds
sub
ax,ax
push
ax
mov
ax,datarea
mov
ds,ax
call
input
cmp
ax,10000d
je
endall
call
bubblesort
call
output
endall: mov
ah,4ch
int
21h
;----------------------------------------
input
proc
lea
dx,mess1
mov
ah,09
int
21h
call
crlf
mov
si,0
mov
cx,count
enter:
call
char_int
dec
cx
cmp
dl,','
je
store
cmp
dl,13
je
exit2
jne
error
store: mov
buf[si],bx
add
si,2
jmp
enter
error:
call
crlf
lea
dx,mess2
mov
ah,09
int
21h
mov
ax,10000d
jmp
exit3
exit2: mov
buf[si],bx
call
crlf
exit3:
ret
input
endp
;-----------------------------------------
bubblesort
proc
mov
cx,count
dec
cx
lg4: mov
di,cx
mov
si,0
lg2: mov
ax,buf[si]
cmp
ax,buf[si+2]
jle
lg3
lg5:
xchg
ax,buf[si+2]
mov
buf[si],ax
lg3:
add
si,2
loop
lg2
mov
cx,di
loop
lg4
ret
bubblesort
endp
;--------------------------------------
output
proc
lea
dx,mess3
mov
ah,09
int
21h
call
crlf
mov
si,0
mov
di,count
next1: mov
bx,buf[si]
cmp
bl,0
jge
next4
mov
dl,'-'
mov
ah,2
int
21h
neg
bx
next4:
call
int_char
mov
dl,','
mov
ah,02
int
21h
add
si,2
dec
di
jnz
next1
call
crlf
ret
output
endp
;---------------------------------------
char_int proc
mov
bx,0
mov
flag,0
newchar: mov
ah,1
int
21h
mov
dl,al
cmp
al,2dh
jnz
next2
mov
flag,1