汇编语言(沈美明,温冬婵)课后答案

mov word ptr [di], 0 mov di, bx pop cx jmp comp exit: ……

13、答: ……

mov dx, 100 mov si, 0 repeat:

mov al, string[si] cmp al, 30h jb goon

cmp al, 39h ja goon

or cl, 20h ; (cl)51 jmp exit goon: inc si dec dx jnz repeat

and cl, 0dfh ; (cl)50 exit: ……

14、答: ……

table dw 100h dup (?)

mdata dw ? ; 存放出现次数最多的数 count dw 0 ; 存放出现次数 ……

mov bx, 100h

mov di, 0 ; di为数组TABLE的指针 next:

mov dx, 0 mov si, 0

mov ax, table[di] mov cx, 100h comp:

cmp table[si], ax jne addr inc dx addr: add si, 2 loop comp cmp dx, count jle chang

mov count, dx mov mdata, ax chang: add di, 2 dec bx jnz next

mov cx, count mov ax, mdata ……

19、答: ……

a dw 15 dup (?)

b dw 20 dup (?) c dw 15 dup (?)

……

mov si, 0 ; si为数组A的指针 mov bx, 0 ; bx为数组C的指针 mov cx, 15 loop1:

mov di, 0 ; di为数组B的指针 push cx mov cx, 20 mov ax, a[si] loop2:

cmp b[di], ax jne no

mov c[bx], ax add bx, 2 jmp next no:

add di, 2 loop loop2 next: add si, 2 pop cx loop loop1

21、答: …… mov dx, 0 lea si, array mov ax, [si] mov bx, [si+2] cmp ax, bx jne next1 inc dx next1:

cmp [si+4], ax jne next2 inc dx next2:

cmp [si+4], bx jne num inc dx num:

cmp dx, 3 jl disp dec dx disp:

mov ah, 2 add dl, 30h int 21h

……

第六章

2、 答:

2、答:

(1) NAME1 NAMELIST < >

(2) MOV AX,DATA ;假设结构变量NAME1定义在数据段DATA中 MOV DS,AX MOV ES,AX ;

MOV AH,10

LEA DX,NAME1 INT 21H ;

MOV CL,NAME1.ACTLEN MOV CH,0

LEA SI,NAME1.NAMEIN LEA DI,DISPFILE CLD

REP MOVSB

6、答: SKIPLINES PROC NEAR PUSH CX PUSH DX MOV CX,AX

NEXT: MOV AH,2 MOV DL,0AH INT 21H MOV AH,2 MOV DL,0DH INT 21H LOOP NEXT POP DX POP CX RET

SKIPLINES ENDP

7、答:

dseg segment

num dw 76,69,84,90,73,88,99,63,100,80 n dw 10 s6 dw 0 s7 dw 0 s8 dw 0 s9 dw 0 s10 dw 0 dseg ends

code segment main proc far

assume cs:code, ds:dseg start: push ds sub ax, ax push ax

mov ax, dseg mov ds, ax

call sub1 ret

main endp

sub1 proc near

push ax push bx push cx push si mov si, 0 mov cx, n next:

mov ax, num[si] mov bx, 10

div bl

mov bl, al cbw

sub bx, 6 sal bx, 1 inc s6[bx] add si,2 loop next pop si pop cx pop bx pop ax ret

sub1 endp

code ends end start

8、答:

data segment maxlen db 40 n db ?

table db 40 dup (?) char db 'a' ; 查找字符’a’ even

addr dw 3 dup (?) data ends

code segment

assume cs:code, ds:data main proc far start: push ds mov ax, 0 push ax

mov ax, data mov ds, ax

lea dx, maxlen mov ah, 0ah

int 21h ; 从键盘接收字符串

mov addr, offset table mov addr+2, offset n mov addr+4, offset char

mov bx, offset addr ; 通过地址表传送变量地址

call count ; 计算CHAR的出现次数 call display ; 显示 ret

main endp

count proc near ; count子程序 push si push di push ax push cx

mov di, [bx] mov si, [bx+2]

mov cl, byte ptr[si]

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4