assembly - 如何在以下代码中找到 AX 和 BX 的最后一个值?
问题描述
mov ax, 15
mov bx, 0Fh
cmp ax,bx
jle a1
mov bx,10
mov cx,3
jmp a2
a1:
move ax,12
mov cx,5
a2:
dec ax
inc bx
loop a2;
解决方案
只需一一阅读说明(例如使用此说明查看每条指令的作用)
mov ax, 15 # ax = 15
mov bx, 0Fh # bx = 15 (since 0Fh = 15)
cmp ax,bx
jle a1 # if (ax <= bx) jump to a1 -> true
mov bx,10 # Therefore these not executes
mov cx,3
jmp a2
a1:
mov ax,12 # ax = 12
mov cx,5 # cx = 5
a2:
dec ax # ax = ax - 1
inc bx # bx = bx + 1
loop a2; # cx = cx - 1 AND if (cx != 0) then jump to a2. Since cx is 5 when
# reaching here therefore looping 4 times which means overall the
# effect is ax = ax - 4 = 12 - 4 = 8 and bx = bx + 4 = 15 + 4 = 19
执行此代码后,AX 为 8,BX 为 19。
基于@ecm 的鹰眼观察进行了更正。
推荐阅读
- javascript - 在 JavaScript 中构建一个自定义的简单解析器以进行进一步处理
- regex - 正则表达式从 node_modules 中排除文件夹
- php - 刷新缓存后opencart 3.0仪表板错误500
- vue.js - How can I access data in asyncData with Nuxt
- angular - 如果满足某些条件,RXJS 停止 Observable 链的传播
- c++ - 如何在 C++ 中为曲面制作邻接矩阵
- jquery - Trigger jQuery script to run if browser window is resized
- ruby - Reset a counter in Ruby
- amazon-web-services - AWS Lambda is seemingly not highly available when invoked from SNS
- javascript - Local search v-data-table Vuetify