实验二 汇编语言程序设计(顺序、多分支、循环)

               

目录

                 实验二  汇编语言程序设计(顺序、多分支、循环)

一. 实验目的

二. 实验内容

三. 实验过程和程序

四. 实验结果(包括必要的截图)

五.实验体会

注:模仿是最深的爱慕


 实验二  汇编语言程序设计(顺序、多分支、循环)

 

一. 实验目的

  1、掌握顺序和循环程序结构和设计方法;

  2、熟悉在PC机上建立、汇编、连接、调试和运行8086/8088汇编语言程序的过程。

二. 实验内容

  1、X、Y、Z、V均为字变量,在X、Y、Z、V字单元中存放是16位带符号数。试编写汇编语言程序完成以下功能:

  ①计算表达式值(V–(X*Y+Z-720))/X;

  ②将上述表达式运算结果整数放在SUM1单元,余数放在SUM2单元。

  2、使用地址表实现如下功能:根据输入的数字1-7,分别显示相应的英文星期名,如果输入其他字符,则重新输入。

  3、求一个班50名学生成绩的平均值、最大值和最小值,并将结果显示出来。

  4、从键盘读入一个字符串,以Enter结束,字符串不超过50个字符,并打印该字符串;查找中间是否有‘masm’子串。如果有,输出‘Yes’;否则,输出‘No’)。 

三. 实验过程和程序

;the source code of the Exp 2.1
stack   segment stack
        db 512 dup(?)
stack   ends

data    segment
        inputX db "input x:",0ah,0dh,'$'
        inputY db "input y:",0ah,0dh,'$'
        inputZ db "input z:",0ah,0dh,'$'
        inputV db "input v:",0ah,0dh,'$'
    
        x dw 0
        y dw 0
        z dw 0
        v dw 0
        sum1 dw 0
        sum2 dw 0
    
        input db 8
        db 1 dup(?)
        db 8 dup(?)
        sign db 0
        outputSum1 db "sum1:",0ah,0dh,'$'
        outputSum2 db "sum2:",0ah,0dh,'$'
data    ends

code    segment 'code'
        assume cs: code, ds: data, ss: stack
start:
        mov ax, data
        mov ds, ax
        mov ax, stack
        mov ss, ax
	
        mov ah, 09h
        lea dx, inputX
        int 21h
        call readInt
        mov word ptr [x], ax
	
        mov ah, 09h
        lea dx, inputY
        int 21h
        call readInt
        mov word ptr [y], ax
	
        mov ah, 09h
        lea dx, inputZ
        int 21h
        call readInt
        mov word ptr [z], ax
	
        mov ah, 09h
        lea dx, inputV
        int 21h
        call readInt
        mov word ptr [v], ax
	
        mov ax, [x]
        mov bx, [y]
        imul bx         ; x*y
        add ax, [z]     ; x*y+z
        sub ax, 720     ; x*y+z-720
        mov bx, [v]
        sub bx, ax      ; v-(x*y+z-720)
        mov ax, bx      
        cwd
        mov bx, [x]     
        idiv bx          ; (v-(x*y+z-720))/x
        mov [sum1], ax
        mov [sum2], dx
	
        lea dx, outputSum1
        mov ah, 09h
        int 21h
	
        mov ax, [sum1]
        call prinIint
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
	
        lea dx, outputSum2
        mov ah, 09h
        int 21h
	
        mov ax, [sum2]
        call prinIint
	
        mov ah, 4ch
        int 21h
readInt:
        pushf
        push bx
        push cx
        push dx
        push si
	
        lea dx, input
        mov ah, 0ah
        int 21h
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
	
        mov ax, 0
        xor cx, cx
        mov cl, [input+1]
        lea si, [input+2]
        mov byte ptr [sign], 0
        cmp byte ptr[si], '-'
        jnz next1
        inc si
        dec cx
        mov byte ptr [sign], 1
next1:
        mov ax, 0
loop1:
        mov bx, 10
        mul bx
        xor bx, bx
        mov bl, [si]
        sub bl, '0'
        add ax, bx
        inc si
        loop loop1
	
        cmp byte ptr [sign], 1
        jnz next2
        xor bx, bx
        sub bx, ax
        mov ax, bx
	
next2:
        pop si
        pop dx
        pop cx
        pop bx
        popf
        ret
prinIint:
        pushf
        push bx
        push cx
        push dx
        push si
	
        mov si, ax
        cmp ax, 0
        jge skip2
        mov dl, '-'
        mov ah, 02h
        int 21h
        mov ax, 0
        sub ax, si
skip2:
        cmp ax, 0
        jne skip1
        push ax
        mov cx, 1
        jmp next3_end
skip1:
        mov cx, 0
next3:
        cmp ax, 0
        je next3_end
        mov dl, 10
        div dl
        xor bx, bx
        mov bl,ah
        push bx
        mov ah, 0
        inc cx
        jmp next3
	
next3_end:
        xor dx, dx
        pop dx
        add dl, 48
        mov ah, 02h
        int 21h
        loop next3_end
        pop si
        pop dx
        pop cx
        pop bx
        popf
        ret
	
code ends
        end start

 

;the source code of the Exp 2.2
stack   segment stack
        db 512 dup(?)
stack   ends

data    segment
        address dw l1, l2, l3, l4, l5, l6, l7
        s1 db 'Monday $'
        s2 db 'Tuesday $'
        s3 db 'Wednesday $'
        s4 db 'Thursday$'
        s5 db 'Friday$'
        s6 db 'Startday$'
        s7 db 'Sunday$'
        input db 'Please input a number between 1 to 7:',0ah,0dh,'$'
data    ends
        
code    segment 'code'
        assume cs: code, ds: data, ss: stack
start:  
        mov ax, data
        mov ds, ax
        mov ax, stack
        mov ss, ax
start1: 
        lea dx, input
        mov ah, 09h
        int 21h
	
        mov ah, 01h
        int 21h
	
        mov bl, al
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
	
        mov al, bl
        sub al, '0'
        cmp al, 1
	
	
        jb start1
        cmp al,7
        ja start1
	
        dec al
        mov ah, 0
        mov bx,ax
        shl bx, 1
        jmp address[bx]

l1:
        lea dx,s1
        jmp s
l2:
        lea dx, s2
        jmp s
l3:
        lea dx, s3    
        jmp s
l4:
        lea dx, s4
        jmp s
l5:
        lea dx, s5
        jmp s
l6:
        lea dx, s6
        jmp s
l7:
        lea dx, s7
s:
        mov ah, 09h
        int 21h
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
   
        mov ah, 4ch
        int 21h

code ends
        end start

 

;the source code of the Exp 2.3
stack   segment stack
        db 512 dup(?)
stack   ends

data    segment
        inputMSG db "input:", 0ah, 0dh, '$'
        max dw 0
        min dw 100
        average dw 0
        input db 8
        db 1 dup(?)
        db 8 dup(?)
        sign db 0
        output1 db "average:", 0ah, 0dh, '$'
        output2 db "max:", 0ah, 0dh, '$'
        output3 db "min:", 0ah, 0dh, '$'
data    ends

code    segment 'code'
        assume cs: code, ds: data, ss: stack
start:
        mov ax, data
        mov ds, ax
	
        mov cx, 50
L1:
        lea dx, inputMSG
        mov ah, 09h
        int 21h
        call readInt
        cmp ax, [max]
        jg max1
        jmp skip11
max1:
        mov [max], ax
skip11:
        cmp [min], ax
        jg min1
        jmp skip22
min1:
        mov [min], ax
skip22:
        add [average], ax
        loop L1
	
        mov ax, [average]
        cwd
        mov bx, 50
        idiv bx
        mov [average], ax
	
        lea dx, output1
        mov ah, 09h
        int 21h
	
        mov ax, [average]
        call printInt
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
	
        lea dx, output2
        mov ah, 09h
        int 21h
	
        mov ax, [max]
        call printInt
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
	
        lea dx, output3
        mov ah, 09h
        int 21h
	
        mov ax, [min]
        call printInt
	
        mov ah, 4ch
        int 21h
readInt:
        pushf
        push bx
        push cx
        push dx
        push si
	
        lea dx, input
        mov ah, 0ah
        int 21h
	
        mov dl, 0ah
        mov ah, 02h
        int 21h
	
        mov dl, 0dh
        mov ah, 02h
        int 21h
	
        mov ax, 0
        xor cx, cx
        mov cl, [input+1]
        lea si, [input+2]
        mov byte ptr [sign], 0
        cmp byte ptr[si], '-'
        jnz next1
        inc si
        dec cx
        mov byte ptr [sign], 1
next1:
        mov ax, 0
loop1:
        mov bx, 10
        mul bx
        xor bx, bx
        mov bl, [si]
        sub bl, '0'
        add ax, bx
        inc si
        loop loop1
	
        cmp byte ptr [sign], 1
        jnz next2
        xor bx, bx
        sub bx, ax
        mov ax, bx
	
next2:
        pop si
        pop dx
        pop cx
        pop bx
        popf
        ret
	
printInt:
        pushf
        push bx
        push cx
        push dx
        push si
	
        mov si, ax
        cmp ax, 0
        jge skip2
        mov dl, '-'
        mov ah, 02h
        int 21h
        mov ax, 0
        sub ax, si
skip2:
        cmp ax, 0
        jne skip1
        push ax
        mov cx, 1
        jmp next3_end
skip1:
        mov cx, 0
next3:
        cmp ax, 0
        je next3_end
        mov dl, 10
        div dl
        xor bx, bx
        mov bl,ah
        push bx
        mov ah, 0
        inc cx
        jmp next3
	
next3_end:
        xor dx, dx
        pop dx
        add dl, 48
        mov ah, 02h
        int 21h
        loop next3_end
        pop si
        pop dx
        pop cx
        pop bx
        popf
        ret
	
code ends
        end start

 

;the source code of the Exp 2.4
stack   segment stack
        db 512 dup(?)
stack   ends

data    segment
        data2 db 50, ?, 50 dup('$')
        string db 'yes', 0ah, 0dh, '$'
        string1 db 'no', 0ah, 0dh, '$'
data    ends


code segment 
        assume cs: code, ds: data, ss: stack
start: 
        mov ax, data
        mov ds, ax
        mov ax, stack
        mov ss, ax
	
        mov ah, 0ah
        mov dx, offset data2
        int 21h
	
        mov ah, 02h
        mov dl, 0ah
        int 21h
	
        mov ah, 02h
        mov dl, 0dh
        int 21h	
	

        mov dx, offset data2+2
        mov ah, 09h
        int 21h
	
        mov ah, 02h
        mov dl, 0ah
        int 21h
	
        mov ah, 02h
        mov dl, 0dh
        int 21h	
	
        mov al, 0h
        mov cx, 47
        mov di, 0
again: 
        mov al, [ di + 2 ]
	    cmp al, 61h
		jnz next
		mov al, [ di + 3] 
		cmp al, 73h
		jnz next
		mov al, [ di + 4 ]
        cmp al, 6dh
        jnz next
		jmp yes

	
next: 
        add di, 1
	    loop again
		mov dx, offset string1
	    mov ah, 09h
	    int 21h
		jmp endcode
yes:		
        mov dx, offset string
	    mov ah, 09h
	    int 21h
endcode:   
        mov ax, 4c00h
        int 21h
	   
code ends
        end start

 

四. 实验结果(包括必要的截图)

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第1张图片 图 1 题2.1运行截图①

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第2张图片 图 2 题2.1运行截图②

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第3张图片 图 3 题2.2运行截图①

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第4张图片 图 4 题2.2运行截图②

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第5张图片 图 5 题2.3运行截图①

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第6张图片 图 6 题2.3运行截图②

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第7张图片 图 7 题2.4运行截图①

 

实验二 汇编语言程序设计(顺序、多分支、循环)_第8张图片 图 8 题2.4运行截图②

 

  五.实验体会

   汇编太难了,这四个题目如果不查资料一个都弄不出来。上课听得很过瘾,下课啥也不会做。

       

 注:模仿是最深的爱慕

你可能感兴趣的:(8086汇编,合肥工业大学,汇编语言,上机实验,顺序,多分支,循环)