assembly - 将索引寄存器分配给通用寄存器
问题描述
我将数组 (arr) 中的每个值除以 2,以检查除法的提示并确定它是奇数还是偶数。问题是每当我将 arr (1) 的第一个值分配给 reg ax 时,存储在 reg ax 中的值是 0201h 而不是 0001h。我真的不明白为什么 0201 被存储而不是 0001。
arr db 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
LEA SI, arr
mov ax,[SI] ; the value 0201h is stored instead of 0001h
原始代码
.Model small
.stack 64
.data
arr db 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
countEven db ?
avgResult db ?
.code
;description
Main PROC Far
mov ax,@data
mov ds,ax
LEA SI, arr
mov countEven, 0
mov cx,10 ;the size of the array
mov bh,2 ;the value 2 to be divided by
mov dx,0 ;the sum container
loop1: mov ax,[SI]
DIV bh
cmp ah,1 ;if ah = 1, then value within ax was odd (reminder of division by 2 is 1)
JE skip
add dx,[SI]
Inc countEven
skip: add SI,1
Loop loop1
mov ax,dx ;ax contains the sum
mov bh,countEven;bx contains the no. of even elements
div bh ;ax is the final avg result of the even numbers, where ax=ax/bx
mov avgResult, al
MOV AH,4CH
INT 21H
Main ENDP
End Main
解决方案
推荐阅读
- python - Boost.Python 类继承自 Python 类型
- python - Python 正则表达式:为什么我的模式不匹配?
- ruby-on-rails - Markdown 渲染换行符
- actionscript-3 - Adobe Animate 2019 错误?Air Mobile 开发层DepthEnabled 错误#1056:
- reactjs - 在反应原生 API 请求中上传 base64 图像
- monaco-editor - 摩纳哥:从自动完成/智能感知中删除 Web API?
- javascript - 向上滚动时检测元素是否可见
- c++ - C++派生类构造函数
- javascript - node.js 和前端 Web 应用程序的单独 babel 配置是同一个项目
- html - 使用 flexbox 垂直对齐单个元素是否可以接受?