this code is supposed to calculate : p/4+v/8 using shift operations

Data Segment
Db p
Db v
Db q
Data ends
Code Segment
Assume cs:code,ds:data
Start: mov ax,p
       Shr ax,01
Mov cl,02
Shr ax,cl
Mov bx,ax
Mov ax,v
Shr ax,01
Mov cl,03
Shr ax,cl
Mov dx,q
add bx
Mov q,ax
Code ends
end

my main question is : for me it seems like we're calculating p/8+v/16?!!!1 because i think there are 2 shift operations that are not needed

有帮助吗?

解决方案

That snippet of code calculates p/8 + v/16 as you said.

Every time you shift 1 bit to the right is like you were doing the integer division by 2.

So, you should remove the SHR ax,01 from both locations to get p/8 + v/16

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top