分析:
由题意,要求利用地址表实现跳转,判断并显示bl中‘1’的位置,由于题目中已经说明了bl二进制数中只有一位是‘1’,即bl是十六进制数01h,02h,04H,08h,10h,20h,40h,80h八个数中的一个,故利用分支结构实现八选一的跳转,利用循环分别判断bl是哪一个数,用地址表table存储对应的执行语句标号,每一个执行语句实现对应字符串的输出,输出“The x Bit is 1”,表示从bl寄存器从低位到高位第几位是‘1’,用数组array存储八个待比较十六进制数的值,用si寄存器相对寻址,逐渐往后递推比较。
代码:
stack segment
stack ends
data segment
msg1 db 'The 1 Bit is 1,BL: 00000001',0dh,0ah,'$'
msg2 db 'The 2 Bit is 1,BL: 00000010',0dh,0ah,'$'
msg3 db 'The 3 Bit is 1,BL: 00000100',0dh,0ah,'$'
msg4 db 'The 4 Bit is 1,BL: 00001000',0dh,0ah,'$'
msg5 db 'The 5 Bit is 1,BL: 00010000',0dh,0ah,'$'
msg6 db 'The 6 Bit is 1,BL: 00100000',0dh,0ah,'$'
msg7 db 'The 7 Bit is 1,BL: 01000000',0dh,0ah,'$'
msg8 db 'The 8 Bit is 1,BL: 10000000',0dh,0ah,'$'
table dw disp1,disp2,disp3,disp4,disp5,disp6,disp7,disp8
array db 01h,02h,04h,08h,10h,20h,40h,80h
data ends
code segment
assume cs: code, ds: data
start: mov ax,data
mov ds,ax
mov si,offset array
mov bl,02h
mov al,bl ;初始化bl
mov cl,8
mov bx,0
again: cmp al,[si]
jnz nott
jmp table[bx]
nott: inc bx
inc bx
inc si
loop again
done: mov ah,09h
int 21h
mov ah,4ch
int 21h
disp1: lea dx,msg1
jmp done
disp2: lea dx,msg2
jmp done
disp3: lea dx,msg3
jmp done
disp4: lea dx,msg4
jmp done
disp5: lea dx,msg5
jmp done
disp6: lea dx,msg6
jmp done
disp7: lea dx,msg7
jmp done
disp8: lea dx,msg8
jmp done
code ends
end start
经典地址表,必须拿下!