test ax,0001
jz class
test bx,0001
jz exit
xchg bx,a
mov b,bx
jmp exit
class: test bx,0001
jz exit
inc b
inc a
exit: ret
main endp
cseg ends
end start
5. 把0~10010之间的30个数,存入首地址为GRAD的字数组中,GRAD+i表示学号为i+1的学生成绩。另一个数组RANK是30个学生的名次表,其中RANK+I的内容是学号为i+1的学生的名次。试编写程序,根据GRAD中的学生成绩,将排列的名次填入RANK数组中(提示:一个学生的名次等于成绩高于这个学生的人数加1)。
答案:
dseg segment
grade dw 30 dup(?)
rank dw 30 dup(?)
dseg ends
cseg segment
main proc far
assume cs:cseg, ds:dseg, es:dseg
start: push ds
sub ax,ax
push ax
mov ax,dseg
mov ds,ax
mov es,ax
begin: mov di,0
mov cx,30
loop1: push cx
mov cx,30
mov si,0
mov ax,grade[di]
mov dx,0
loop2: cmp grade[si],ax
jbe go_on
inc dx
go_on: add si,2
loop loop2
pop cx
inc dx
mov rank[di],dx
sdd di,2
loop loop1
ret
main endp
cseg ends
end start
6. 分析下列程序的功能,写出堆栈最满时各单元的地址及内容。
SSEG SEGMENT 'STACK' AT 1000H ; 堆栈的段地址为1000H
DW 128 DUP(?)
TOS LABEL WORD
SSEG ENDS
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DSEG SEGMENT
DW 32 DUP(?)
DSEG ENDS
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CSEG SEGMENT
MAIN PROC FAR
ASSUME CS:CSEG, DSSEG,SS:SSEG
START: MOV AX,SSEG
MOV SS,AX
MOV AX,DSEG
MOV DS,AX
MOV AX,4321H
CALL HTOA
RETN: MOV AH,4CH
INT 21H
MAIN ENDP
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
HTOA PROC NEAR
CMP AX,15
JLE B1
PUSH AX
PUSH BP
MOV BP,SP
MOV BX,[BP+2]
AND BX,0FH
MOV [BP+2],BX
POP BP
MOV CL,4
SHR AX,CL
CALL HTOA
B1: POP AX
B2: ADD AL,30H
JL PRT
ADD AL,07
PRT: MOV DL,AL
MOV AH,2
INT 21H
RET
HTOA ENDP
CSEG ENDS
; ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
END START
答案:
1000:0F2H
B1
1000:0F4H