汇编语言实验报告 下载本文

imul word ptr Y mov cx, dx mov bx, ax mov ax, Z cwd add bx, ax adc cx, dx mov ax, 21CH cwd sub bx, ax sbb cx, dx mov ax, V

cwd sub ax, bx sbb dx, cx idiv word ptr X mov word ptr SUM1, ax mov word ptr SUM2, dx mov ah,4ch

int 21h

code

ends

end start

第二题:

stack segment stack dw 512 dup(?) stack ends

data segment

tip db 'Input number(1~7, 0 for quit):', '$' msg1 db 'Monday', 0DH, 0AH, '$' msg2 db 'Tuesday', 0DH, 0AH, '$' msg3 db 'Wednesday',0DH, 0AH, '$' msg4 db 'Thursday', 0DH, 0AH, '$' msg5 db 'Friday', 0DH, 0AH, '$' msg6 db 'Saturday', 0DH, 0AH, '$' msg7 db 'Sunday', 0DH, 0AH, '$'

table dw show1, show2, show3, show4, show5, show6, show7 data ends

code segment

assume cs:code,ds:data,ss:stack start:

mov ax,data mov ds,ax getnum:

; 打印提示信息 mov dx, offset tip mov ah, 09H int 21H

; 用户输入数字 mov ah, 01H int 21H mov bl, al

; 换行保持美观 mov ah, 02H mov dl, 0DH int 21H mov ah, 02h mov dl, 0AH int 21H

; 非法数值重新输入 cmp bl, '0' jb getnum cmp bl, '7' ja getnum

; 输入'0'直接退出 cmp bl, '0' je quit

and bx, 000FH dec bx

shl bx, 01H jmp table[bx] ; 输出对应单词 print:

mov ah, 09H int 21H jmp getnum quit:

mov ah,4ch int 21h show1:

mov dx, offset msg1

jmp print show2:

mov dx, offset msg2 jmp print show3:

mov dx, offset msg3 jmp print show4:

mov dx, offset msg4 jmp print show5:

mov dx, offset msg5 jmp print show6:

mov dx, offset msg6 jmp print show7:

mov dx, offset msg7 jmp print code ends end start

第三题:

stack segment stack dw 512 dup(?) stack ends

data segment

student db 50 dup(2)

table dw 10000, 1000, 100, 10, 1 NewLine db 0DH, 0AH, '$' MaxStr db 'Max:$' MinStr db 'Min:$'

Average db 'Average:$' data ends

code segment

assume cs:code,ds:data,ss:stack start:

mov ax,data mov ds,ax

call calcAverage call findMax call findMin

mov ah, 4CH int 21H calcAverage:

lea si, student mov cx, 50 mov ax, 0 PlusNext:

add al, [si] adc ah, 0 inc si

loop PlusNext mov bl, 50 div bl mov bl, al xor bh, bh

lea dx, Average mov ah, 09H int 21H call putnum

lea dx, NewLine mov ah, 09H int 21H ret findMax:

lea si, student mov cx, 50 mov al, 0 MaxNext:

cmp al, [si] ja MaxPass mov al, [si] MaxPass: inc si

loop MaxNext mov bl, al xor bh, bh

lea dx, MaxStr mov ah, 09H int 21H call putnum

lea dx, NewLine mov ah, 09H int 21H ret

findMin:

lea si, student mov cx, 50 mov al, 0FFH MinNext:

cmp al, [si] jb MinPass mov al, [si] MinPass: inc si

loop MinNext mov bl, al xor bh, bh

lea dx, MinStr mov ah, 09H int 21H call putnum

lea dx, NewLine mov ah, 09H int 21H ret putnum: mov cx, 5

lea di, table next:

mov ax, bx mov dx, 0H div word ptr[di] test al, 0H mov bx, dx add al, '0' mov dl, al mov ah, 02H int 21H add di, 2 loop next ret code ends end start

四. 实验结果(包括必要的截图) 第一题: