加载中...

2023春汇编实验


实验一 熟悉上机环境、顺序程序设计

1、 上机题目:两个32位数的相加运算 内容: DAT开始的单元中存放两个32位二进制 数,两个数相加后结果存入SUM单元中。 ( SUM为32位 )

DAT DWORD X1,X2(自己设定数据)

SUM DWORD ?

要求: 1)熟悉上机环境 2)熟练掌握简单的顺序程序设计方法

include irvine32.inc
.data
  dat dword 11223344h,44556677h
  sum dword ?
.code
  main proc
  mov eax,dword ptr dat
  add eax,dword ptr dat+4
  mov dword ptr sum,eax
  exit
  main endp
  end main

实验 二 分支程序设计

1、上机题目: 求最大数 内容:DAT开始的字单元中存放N(N>1)个有符号数,求出最大数存入MAX单元中。

DAT word X1,……,XN(数据自己设定)

MAX word ?

要求:熟练掌握分支程序设计方法

include irvine32.inc
.data
  dat word x1,...,x2
  max word ?
.code
  main proc
  mov ecx,lengthof dat-1
  mov esi,0
  mov ax,dat[esi]
again:
  add esi,2
  cmp ax,dat[esi]
  jnl next
  mov ax,dat[esi]
next:
  dec ecx
  jnz again
  mov max,ax
  mov eax,dword ptr max
  call writeint

  exit
  main endp
  end main

实验(三) 循环程序设计

1、上机题目:数据查找 内容:TAB开始的字节单元中存放N个无符号数,dat单元存放一个已知数据X,现从TAB中查找是否存在数据X,如果存在,NO单元存放该数据在TAB中的序号,否则NO单元存放0FFH 。

TAB byte X1,……,XN(数据自己设定)

dat byte x

no byte ?

要求:1)熟练掌握循环程序设计方法 2)理解循环判断条件

include irvine32.inc
.data
	tab byte x1,....,x2
	dat byte ?
	no byte ?
.code
main proc
	mov edl,0
	mov ecx,lengthof tab
	mov esi,0
	mov eax,dat
again:
	cmp tab[esi],al
	jz EXT1
	inc esi
	inc dl
	dec ecx
	cmp ecx,0
	jnz again
EXT1:
	jecxz Nfound
found:
	mov no,dl
	jmp EXT2
Nfound:
	mov no,0ffh
EXT2:
	movsx eax,no
	call writeint
exit
main endp
end main

上机题目:无符号数排序

内容:TAB开始的单元中存放N(N>1)个字节无符号数,请按照从大到小排序后,存入DAT单元中。(注意:TAB数据保持不变)

TAB byte X1,……,XN(数据自己设定)

DAT byte N DUP(?)

要求:1)熟练掌握循环程序设计方法 2) 理解循环判断条件 3) 熟练掌握双重循环结构

include irvine32.inc
.data
	tab byte x1,....,x2
	dat byte n DUP(?)
.code
main proc
	mov ecx,lengthof tab
copy:
	mov al,tab[ecx]
	mov dat[ecx],al
	loop copy
	mov al,tab[ecx]
	mov dat[ecx],al
	mov ecx,lengthof tab
	dec ecx
again1:
	mov edi,ecx
	mov ebx,0
again2:
	mov al,dat[ebx]
	cmp al,dat[ebx+1]
	jae next
	xchg al,dat[ebx+1]
	mov dat[ebx],al
next:
	inc ebx
	dec ecx
	cmp ecx,0
	jnz again2
	mov ecx,edi
	dec ecx
	cmp ecx,0
	jnz again1
	mov ecx,lengthof dat
	mov esi,0
pt:
	mov al,dat[esi]
	call writehex
	call crlf
	inc esi
	cmp esi,ecx
	jnz pt
exit
main endp
end main

实验 四 子程序设计

  1. 上机题目:代码转换

内容:用子程序设计的方法,分别把BUF字单元中的四位十六进制数转换为ASCII码存入MAS开始的单元中,并在终端上显示MAS开始的4个字节单元。

BUF word X

MAS byte 4 DUP(?)

要求:1)熟练掌握子程序设计方法 2)掌握参数传递方法 3)掌握子程序获取参数方法

include irvine32.inc
.data
	buf word ?
	mas byte n dup(?)
.code
main proc
	push buf
	push offset mas
	call decbin
	exit
	main endp
decbin proc
	push ebp
	mov ebp,esp
	push esi
	push eax
	push ecx
	push edx
	push ebx
	mov esi,0
	mov ecx,4
	mov ebx,[ebp+12]
	mov edi,[ebp+8]
again:
	mov dx,word ptr [ebx]
	rol dx,4
	mov word ptr [ebx],dx
	and dl,0fh
	cmp dl,0ah
	jb num
	add dl,7
num:
	add dl,30h
	mov byte ptr [edi+esi],dl
	movzx eax,dl
	call writeint
	call crlf
	inc esi
	dec ecx
	cmp ecx,0
	jnz again
	pop edx
	pop ebx
	pop ecx
	pop eax
	pop esi
	pop ebp
	ret 8
	decbin endp
end main

上机题目2:键盘输入

内容:从键盘输入一串字母并保存在string开始的地址单元,要求将该字符串中的大写字母转化为小写字母后用子程序实现,在终端上依次显示该串字母的 ASCII码。

string byte n dup(?)

要求:1)熟练掌握子程序设计方法,会画子程序、主程序流程图 2)掌握参数传递方法以及子程序获取参数的方法

include irvine32.inc
.data
	string byte n dup(?)	
	count dd ?
.code
main proc
	lea edx,string
	mov ecx,10
	call readestring
	mov count,eax
	call change
	mov ecx,0
	
pt:
	movzx eax,string[ecx]
	inc ecx
	call writeint
	call crlf
	cmp ecx,count
	jnz pt
	main endp
change proc
	push esi
	push edx
	push ecx
	push eax
	mov esi,0
again1:
	mov dl,string[esi]
	cmp dl,61h
	jnb again2
	add dl,20h
	mov string[esi],dl
again2:
	inc esi
	cmp esi,count
	jnz again1
	pop eax
	pop ecx
	pop edx
	pop esi
	ret
	chang endp
end main

实验(五) 综合程序设计

1、上机题目:将从键盘输入的N个无符号数保存到数组DAT ,找出N个无符号数中的偶数存放到数组P,统计并在终端上显示数组P的数据个数no。

DAT word n dup (?)

P word n dup (?)

no word ?

要求:1、求偶数数组P的功能用子程序实现 2、画主程序及子程序流程图 3、熟练掌握综合程序设计方法

include irvine32.inc
.data
	DAT word n dup(?)
	p word n dup(?)
	no word ?
.code
main proc
	call readint
	mov ecx,eax
	push ecx
	mov esi,0
cin:
	call readint
	mov dat[esi],ax
	add esi,type dat
	loop cin

   

​         	push offset dat
​         	push offset p
​         	call pno
​         	mov ax,no
​         	call writeint
​         	exit
​         	main endp


​         

​     pno proc
​     	push ebp
​     	mov ebp,esp
​     	push eax
​     	push ecx
​     	push edx
​     	push esx
​     	push ebx
​     	mov ecx,[ebp+16]
​     	mov ebx,[ebp+12]
​     	mov esi,[ebp+8]
​     again1:
​     	mov dx,[ebx]
​     	and dl,1
​     	cmp dl,0
​     	jne next
​     	mov dx,[ebx]
​     	mov [esi],dx
​     	add esi,type p
​     	inc no
​     next:
​     	add ebx,type dat
     	loop again
​     	pop esx
​     	pop ebi
​     	pop edx
​     	pop ecx
​     	pop eax
​     	pop ebp
​     	ret 12
​     	pno endp
​     end main

​ 2、上机题目:将从键盘输入的N个有符号数保存到数组TAB ,找出N个有符号数中绝对值大于X的最小负奇数存放到Min单元,如果没有找到则Min单元存放0。在终端上显示Min的绝对值。 TAB Dword n dup(?)

​ X Dword xx(无符号数,自己设定)

​ Min Dword ?

​ 要求:1、求数据Min的功能用子程序实现 2、画主程序及子程序流程图 3、熟练掌握综合程序设计方法

     include irvine32.inc
​     N=8
​     .data
​     	tab dd N dup(?)
​     	x dd 5
​     	min dd ?
​     .code
​     main proc
​     	mov ecx,N
​     	mov esi,0
​     cin:
​     	call readint
​     	mov dword ptr tab[esi],eax
​     	add esi,4
​     	loop cin


​         
​         	mov ecx,N
​         	push ecx
​         	lea edi,tab
​         	push edi
​         	push x
​         	lea edi,min
​         	push edi
​         	call qmin
​         	 

​     	mov eax,min
​     	call writeint
​     	exit
​     	main endp
​     
​     qmin proc
​     	push ebp
​     	mov ebp,esp
​     	push eax
​     	push ecx
​     	push edx
​     	push edi
​     	push esi
​     
​     	mov ecx,dword ptr [ebp+20]	;N
​     	mov esi,dword ptr [ebp+16]	;tab
​     	mov edi,dword ptr [ebp+12]	;x
​     	mov edx,dword ptr [ebp+8]		;min
​     
​     again:
​     	mov eax,dword ptr [esi]
​     	test eax,1
​     	je next
​     	test eax,8000000h
​     	je next
​     	neg eax
​     	cmp eax,edi
​     	jbe next
​     	neg eax
​     
​     	cmp eax,dword ptr [edx]
​     	jge next
​     	mov dword ptr [edx],eax
​     
​     next:
​     	add esi,4
​     	loop again


​         
​         	pop esi
​         	pop edi
​         	pop edx
​         	pop ecx
​         	pop eax
​         	pop ebp
​         	ret 16
​         	qmin endp
​         

​     end main

​ 原文链接:https://blog.csdn.net/Lurume/article/details/129997995


文章作者: Lurume
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Lurume !
  目录