CMU Computer Systems: Machine-Level Programming (Control)

Control: Condition codes

Processor State
  • Information about currently executing program
    • Temporary data
    • Location of runtime stack
    • Location of current code control point
    • Status of recent tests
Condition Codes (Implicit Setting)
  • Single bit registers
    • CF, SF, ZF, OF
  • Implicitly set by arithmetic operations
  • Not set by leaq instruction
Condition Codes (Explicit Setting)
  • Explicit Setting by Compare Instruction
    • cmpq b,a like computing a-b without setting destiation
  • Explicit Setting by Test instruction
    • testq b,a like computing a&b without setting destination
    • Sets condition codes based on value of a&b
Reading Condition Codes
  • SetX Instructions
    • Set low-order byte of destination to 0 or 1 based on combinations of condition codes
  • One of addressable byte registers
    • Does not alter remaining bytes
    • Typically use movzbl to finish job

Conditional branches

Jumping
  • jX Instructions
    • Jump to different part of code depending on condition codes
Expressing with Goto Code
  • C allows goto statement
  • Jump to position designated by label
Using Conditional Moves
  • Conditional Move Instructions
    • Instruction supports
    • Supported in post-1995x86 processors
    • GCC tries to use them
Bad Cases for Conditional Move
  • Expensive Computations
  • Risky Computations
  • Computations with side effects

Loops

Do-While Loop
  • Use conditional branch
While Loop
  • Initial goto starts loop at test
  • Initial conditional guards entrance to loop
For Loop
  • Init Test Update Body

Switch Statements

Prototype
  • Multiple case labels
  • Fall through cases
  • Missing cases
Structure
  • From Jump Table to Jump Targets
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值