当前位置: 首页 > news >正文

检察机关门户网站建设情况产品线上推广方式都有哪些

检察机关门户网站建设情况,产品线上推广方式都有哪些,海尔集团网站是怎么做的,亚马逊网站建设历程文章目录mov 指令解码jmp 指令解码这篇文章举例来讲讲 mov 指令和 jmp 指令解码函数的实现,其他的指令解码函数都与这些类似。mov 指令解码 以 mov 指令中的一类:寄存器/内存 到/从 寄存器,来详细说明解码函数的实现。 机器指令格式如下&am…

文章目录

    • mov 指令解码
    • jmp 指令解码

这篇文章举例来讲讲 mov 指令和 jmp 指令解码函数的实现,其他的指令解码函数都与这些类似。

mov 指令解码

以 mov 指令中的一类:寄存器/内存 到/从 寄存器,来详细说明解码函数的实现。

机器指令格式如下:
在这里插入图片描述
各字段的含义如下:

w 1 bit  w=0表示数据宽度是字节,w=1表示数据宽度是字
d 1 bit   d=0表示reg是源操作数,d=1表示reg是目的操作数
reg 3 bitsREG W=0 W=1000 AL AX001 CL CX010 DL DX011 BL BX100 AH SP101 CH BP110 DH SI111 BH Dl
mod 2 bits00 MemoryMode,nodisplacement follows01 MemoryMode,8-bit displacementfollows10 MemoryMode,16-bit displacementfollows11 RegisterMode(no displacement)
rm 3 bitsMOD=11              EFFECTIVE ADDRESS CALCULATIONR/M w=0 w=1   R/M  MOD=00        MOD=01          MOD=10000 AL AX     000 (BX)+(SI)     (BX)+(SI)+D8    (BX)+(SI)+D16001 CL CX     001 (BX)+(DI)     (BX)+(DI)+D8    (BX)+(DI)+D16010 DL DX     010 (BP)+(SI)     (BP)+(SI)+D8    (BP)+(SI)+D16011 BL BX     011 (BP)+(DI)     (BP)+(DI)+D8    (BP)+(DI)+D16100 AH SP     100 (SI)          (SI)+D8         (SI)+D16101 CH BP     101 (DI)          (DI)+D8         (DI)+D16110 DH SI     110 DIRECTADDRESS (BP)+D8         (BP)+D16111 BH DI     111 (BX)          (BX)+D8         (BX)+D16

解码函数 decodeMovRegOrMemoryToFromReg 的目的就是将它转换为如下形式的中间指令格式:

指令类型,指令详细类型,[源操作数],[目的操作数]

decodeMovRegOrMemoryToFromReg 函数首先检测输入的机器指令的长度:

func decodeMovRegOrMemoryToFromReg(instructions []byte) []byte {/* 0b100010dw,mod reg r/m, (DISP-LO ), (DiSP-HI)*/decodegth := len(instructions)if decodegth < 2 {return nil}dispLen := lenDisplacement(instructions[1])if decodegth < 2+dispLen {return nil}....
}

由上文机器指令格式可知,这个指令至少有 2 字节长。如果长度达到 2 字节,再调用 lenDisplacement 获取偏移量的长度。如果指令长度达不到指令格式的要求,说明不是一条完整的指令,那就返回 nil。

lenDisplacement 的实现如下:

/* mod xxx r/m, (DISP-LO ), (DiSP-HI) */
func lenDisplacement(secondByte byte) int {mod := (secondByte & 0b11000000) >> 6rm := secondByte & 0b111if mod == 0b11 {return 0}if mod == 0b00 { /* mov bx, [1]*/if rm == 0b110 {return 2}return 0}if mod == 0b01 {return 1}return 2
}

就是根据 mod 和 rm 字段的含义返回偏移量的长度。

然后就是根据 d、w、mod、rm、reg 字段的含义,确定指令详细类型和操作数,将中间形式的指令格式返回:

	decodedInstructions := []byte{InstructionMov}// return 2 + dispLend := (instructions[0] & 0b10) >> 1w := instructions[0] & 0b1mod := (instructions[1] & 0b11000000) >> 6reg := (instructions[1] & 0b111000) >> 3rm := instructions[1] & 0b111switch mod {case 0b11: //RegisterMode(no displacement)if w == 0 {decodedInstructions = append(decodedInstructions, MovReg8ToReg8)} else {decodedInstructions = append(decodedInstructions, MovReg16ToReg16)}if d == 0 { //reg是源操作数decodedInstructions = append(decodedInstructions, reg)decodedInstructions = append(decodedInstructions, rm)} else {decodedInstructions = append(decodedInstructions, rm)decodedInstructions = append(decodedInstructions, reg)}default:if d == 0 {if w == 0 {decodedInstructions = append(decodedInstructions, MovReg8ToMemory)} else {decodedInstructions = append(decodedInstructions, MovReg16ToMemory)}decodedInstructions = append(decodedInstructions, reg)decodedInstructions = append(decodedInstructions,decodeMemoryOperand(mod, rm, instructions[2:])...)} else {if w == 0 {decodedInstructions = append(decodedInstructions, MovMemoryToReg8)} else {decodedInstructions = append(decodedInstructions, MovMemoryToReg16)}decodedInstructions = append(decodedInstructions,decodeMemoryOperand(mod, rm, instructions[2:])...)decodedInstructions = append(decodedInstructions, reg)}}return decodedInstructions

比如,当 mod 字段为 0b11 时,表示两个操作数都是寄存器,如果 d 为 0,那么 reg 字段就是源操作数,rm 字段就是目的操作数。如果 w 为1,那么操作数的宽度就是16位。这时候生成的中间指令格式为:

InstructionMov,MovReg16ToReg16 ,reg , rm

如果 reg 的值是 0,rm 的值是 1,这条指令的源汇编指令就是:

mov ax,cx

就是这么简单。

再看下解码 mov 立即数到内存/寄存器 解码函数 decodeMovImmediateToRegOrMemory 的实现:

func decodeMovImmediateToRegOrMemory(instructions []byte) []byte {/*1100011w, mod 000 rm, [disp-lo] [disp-hi] data [data]*/decodegth := len(instructions)if decodegth < 2 {return nil}w := instructions[0] & 0x1dispLen := lenDisplacement(instructions[1])dataLen := 1if w == 1 {dataLen = 2}if decodegth < 2+dispLen+dataLen {return nil}decodedInstructions := []byte{InstructionMov}mod := (instructions[1] & 0b11000000) >> 6rm := instructions[1] & 0b111if w == 0 {if mod == 0b11 {decodedInstructions = append(decodedInstructions, MovImmediateToReg8)decodedInstructions = append(decodedInstructions, instructions[2])decodedInstructions = append(decodedInstructions, rm)} else {decodedInstructions = append(decodedInstructions, MovImmediate8ToMemory)decodedInstructions = append(decodedInstructions, instructions[decodegth-1])decodedInstructions = append(decodedInstructions,decodeMemoryOperand(mod, rm, instructions[2:decodegth-1])...)}} else {if mod == 0b11 {decodedInstructions = append(decodedInstructions, MovImmediateToReg16)decodedInstructions = append(decodedInstructions, instructions[2])decodedInstructions = append(decodedInstructions, instructions[3])decodedInstructions = append(decodedInstructions, rm)} else {decodedInstructions = append(decodedInstructions, MovImmediate16ToMemory)decodedInstructions = append(decodedInstructions, instructions[decodegth-2])decodedInstructions = append(decodedInstructions, instructions[decodegth-1])decodedInstructions = append(decodedInstructions,decodeMemoryOperand(mod, rm, instructions[2:decodegth-2])...)}}return decodedInstructions
}

其他的都类似。

jmp 指令解码

jmp 指令包含直接转移和条件转移。
decode_jmp.go 中先把所有的指令详细类型定义出来:

const (//非条件转移JmpNotShort           uint8 = iota //16位IP偏移量JmpShort                           //8位IP偏移量JmpDirectIntersegment              //cs 16位,IP 16位JmpReg16                           //IP的值在寄存器中JmpIndirectWithinsegmentJmpIndirectIntersegment//条件转移JmpJoJmpjnoJmpJbJmpJnbJmpJeJmpJneJmpJbeJmpJnbeJmpJsJmpJnsJmpJpJmpJnpJmpJlJmpJnlJmpJleJmpJnleJmpJcxz
)

初始化函数,注册所有的 jmp 指令与它的解码函数:

func init() {//jmpAddDecodeInstruction(0xE9, decodeJmpDirectWithinsegment)AddDecodeInstruction(0xEA, decodeJmpDirectIntersegment)AddDecodeInstruction(0xEB, decodeJmpDirectWithinsegmentShort)AddDecodeInstruction2(0xFF, 0b100, decodeJmpIndirectWithinsegment)AddDecodeInstruction2(0xFF, 0b101, decodeJmpIndirectIntersegment)var firstByte bytefor firstByte = 0x70; firstByte <= 0x7F; firstByte++ {AddDecodeInstruction(firstByte, decodeJmpConditional)}//jcxzAddDecodeInstruction(0xE3, decodeJmpConditional)}

以段内间接转移为例,它的机器指令格式如下:
在这里插入图片描述
对应的解码函数 decodeJmpIndirectWithinsegment 代码如下:

func decodeJmpIndirectWithinsegment(instructions []byte) []byte {/*11111111,mod 1 0 0 r/m,(DISP-LO ) (DISP-HI)*/decodegth := len(instructions)if decodegth < 2 {return nil}dispLen := lenDisplacement(instructions[1])if decodegth < 2+dispLen {return nil}decodedInstructions := []byte{InstructionJmp}mod := (instructions[1] & 0b11000000) >> 6rm := instructions[1] & 0b111if mod == 0b11 {decodedInstructions = append(decodedInstructions, JmpReg16)decodedInstructions = append(decodedInstructions, rm)} else {decodedInstructions = append(decodedInstructions, JmpIndirectWithinsegment)decodedInstructions = append(decodedInstructions,decodeMemoryOperand(mod, rm, instructions[2:])...)}return decodedInstructions
}

如果 mod 是 0b11,则返回的中间形式机器指令为:

InstructionJmp,JmpReg16,rm

条件转移的解码函数就更简单,因为条件转移的机器指令固定 2 个字节:
在这里插入图片描述
只需根据第一个字节确定详细指令类型即可,它的实现如下:

func decodeJmpConditional(instructions []byte) []byte {/*xxxxxxxx,IP-INC8*/if len(instructions) < 2 {return nil}table := map[uint8]uint8{0x70: JmpJo,0x71: Jmpjno,0x72: JmpJb,0x73: JmpJnb,0x74: JmpJe,0x75: JmpJne,0x76: JmpJbe,0x77: JmpJnbe,0x78: JmpJs,0x79: JmpJns,0x7A: JmpJp,0x7B: JmpJnp,0x7C: JmpJl,0x7D: JmpJnl,0x7E: JmpJle,0x7F: JmpJnle,0xE3: JmpJcxz,}return []byte{InstructionJmp, table[instructions[0]], instructions[1]}
}

其他指令的解码函数实现都类似。

后续文章讲解 EU 如何实现执行 mov,jmp 以及一些算数运算指令。

http://www.r43.cn/news/588.html

相关文章:

  • python开发做网站百度权重什么意思
  • 学网站开发工程师难学吗单页网站seo如何优化
  • 做网站开发的经营范围网站正能量免费推广软件
  • 门户网站建设的必要性百度竞价推广的优势
  • 站长工具关键词青岛网站权重提升
  • 做淘口令网站人员优化方案
  • 福州网站排名推广中央人民政府网
  • 网址大全首页济南做seo的公司排名
  • 教学网站在线自测功能怎么做seo优化推广工程师招聘
  • 肇庆住房和城乡建设部网站徐州百度seo排名优化
  • 化工网站建站模板百度关键词优化快速排名软件
  • 网站建设注意事项知乎seo独立站优化
  • 校园网站模版推广普通话的宣传语
  • 木门行业网站该怎么做百度搜索高级搜索
  • 成都哪里做网站备案百度推广费用预算表
  • 网站黑名单win10优化软件
  • 做网站建设的利润真正免费的网站建站平台推荐
  • 建网站支持设备是什么意思今日新闻十大头条内容
  • django 做网站知名品牌营销策略
  • 便宜电商网站建设网络软文范例
  • 小熊代刷推广网站济南seo网络优化公司
  • 跨境电商网站建设开发公众号seo排名优化
  • 专门做有机食品的网站搜索引擎优化的目的是
  • 扬州网站建设外包重庆森林
  • 直接做那个视频网站seo外包杭州
  • 沈阳做网站的科技公司营销培训内容有哪些
  • java网站开发ssh实例好的网络推广平台
  • 网站浏览量怎么查看seo外链代发
  • 做选择网站app拉新项目
  • 免费行情网站推荐太原seo哪家好