王爽第九章依据位移进行转移的jmp指令

assume cs:code

code segment 
	
start:	mov ax,0
	<span style="font-family: Arial, Helvetica, sans-serif;">jmp short s</span>
<span style="white-space:pre">	</span>add ax,1
s:	inc ax
	
mov ax,4c00h
int 21h
code ends
	
end start

其中

jmp short s
相当于

jmp short 8



机器码eb之后的是位移

1、段内近转移的8位位移 = 标号处的地址 - jmp 指令后的第一个指令的地址

2、short 指明此处是的位移是8位位移

3、8位位移的范围为-128 ~ 127,用补码来表示 -128 = 80 127=7f

4、8位位移由编译程序在编译中算出


assume cs:code

code segment 
	
start:	mov ax,0
	mov bx,0
	jmp far ptr s
	db 256 dup (0)
s:	add ax,1
	inc ax
	
mov ax,4c00h
int 21h
code ends
	
end start
其中
jmp far ptr s
的机器码要占5个字节
mov ax,0
mov bx,0
的机器码占6个字节

db 256 dup (0)
占256个字节

一共267个字节,16进制10b

还是同一个段



cs没有变 ip = 6 + 5 + 256 = 267 十六进制 10b

010b 为IP 

1ca5 为cs


assume cs:code

data segment
dd 0
data ends
code segment 
	
start:	mov ax,data
	mov ds,ax
	mov bx,0
	jmp word ptr [bx+1]
mov ax,4c00h
int 21h
code ends
	
end start
其中

jmp word ptr [bx+1]
功能:从内存单元地址处开始存放一个字,是转移的目的偏移地址

assume cs:code

data segment
dd 12345678h
data ends
code segment 
	
start:	mov ax,data
	mov ds,ax
	mov bx,0
	mov [bx],bx
	mov [bx+2],cs
	jmp word ptr ds:[0]
mov ax,4c00h
int 21h
code ends
	
end start
其中 

jmp word ptr ds:[0]
cs= ds[2] ip= ds[1]
功能:从内存单元地址处开始存放着两个字,高地址处的字是转移的目的的地址,低地址处是转移的目的偏移地址

(cs) = (内存单元地址 + 2)

(ip) = ((内存单元地址)



assume cs:code
code segment 

start:	mov ax,2000
	mov ds,ax
	mov bx,0
	s:mov cl,ds:[bx]	
	mov ch,0
	jcxz ok
	inc bx
	jmp short s
	ok:mov dx,bx
mov ax,4c00h
int 21h
code ends
	
end start
其中

jcxz ok
的作用 当(cx) = 0 时, (ip) = (ip) + 8位位移

8位位移 = 标号处的地址 - jcxz 指令后的第一个字节的地址

8位位移的范围为 -128 ~ 127 ,用补码表示

8位位移由编译程序在编译时算出

当(cx) ≠ 0时, 什么都不做(程序向下执行)

jcxz 标号的作用相当于:

if ((cx) == 0) jmp short 标号



cx = 0 ip=c

8位位移 = 11 - c -2 =3


assume cs:code
code segment 

start:	mov ax,2000
	mov ds,ax
	mov bx,0
s:	mov cl,[bx]
	mov ch,0
	inc cx
	inc bx
	loop s
	ok:dec bx
	mov dx,bx
	
mov ax,4c00h
int 21h
code ends
	
end start
其中

loop s
loop 指令为循环指令

操作

(1) (cx) = (cx) - 1

(2) 如果 (cx) ≠ 0, (ip) = (ip) + 8 位位移

8位位移 = 标号处地址 - loop指令后的第一个字节的地址

8位位移的范围为 -128 ~ 127,用补码表示

8位位移由编译程序在编译时算出

如果(cx) = 0 ,什么都不做



e+1 = f 

f6 + 8 + 2 = 100  f6是-10 的补码

标号处 08 loop后 12    08-12 = f6

assume cs:code
code segment 
	
	mov ax,4c00h
	int 21h
start:	mov ax,0
s:	nop
	nop

	mov di,offset s
	mov si,offset s2
	mov ax,cs:[si]
	mov cs:[di],ax

s0:	jmp short s

s1:	mov ax,0
	int 21h
	mov ax,0
	
s2:	jmp short s1
	nop
code ends
	
end start
其中
mov di,offset s
mov si,offset s2
mov ax,cs:[si]
mov cs:[di],ax

jmp short s1

位移位10个字节

复制到
nop
nop
同样位移为10个字节

这条指令会直接让程序中断

assume cs:code,ds:data
data segment
  db 'W','e','l','c','o','m','e',' ','t','o',' ','m','a','s','m','!'
data ends
code segment
start:
  mov ax,data
  mov ds,ax
  
  mov ax,0b800h;b800是显示缓冲区的首地址
  mov es,ax;在显示缓冲区中,偶地址存放字符,奇地址存放字符的颜色属性,默认07,黑底白字
  mov bx,0720h;十六进制a0h表是第1行,第12行就是a0h*bh=6e0h,一行放80个字符,放到中间的话
  ;就40个字符-16个字符的一半=32个字符,一个字符要两个字节,所以偏移地址加上64,也就是40h,
;40h+6e0h=720h
  mov bp,0;从第一个字符读取
  mov cx,16;空格也算字符
s:  mov al,ds:[bp];放字符到寄存器
  mov ah,2h;放字符的颜色属性,显示绿色,10
  mov es:[bx],ax;放字符和字符颜色属性到内存
  
  mov al,ds:[bp]
  mov ah,24h;绿底红字 100100
  mov es:[bx+160],ax ;80个字符占160个字节,到第二行
  
  mov al,ds:[bp]
  mov ah,71h;1110001 白底蓝字
  mov es:[bx+320],ax ;80个字符占160个字节,到第三行
  
  add bx,2;一次送了2个字节,按字来读取
  inc bp;数据段按字节存储,bp就按字节读取
  loop s;循环16次
 
  mov ax,4c00h
  int 21h
code ends
end start


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值