Question

I am using tasm. The question is kind of basic but I can't remember how to do it. Apologies for that, My question is that suppose I have two registers with different values and I wish to combine (merge) them and save the value into a single variable. How would i do that? Suppose ah=01 & al=04 . I wish to merge them into a single value of 14, hex equivalent 0E. Any ideas?

Was it helpful?

Solution

The general idea is to multiply ah by 10 then add to al. Not that the implementation in x86 assembly is somewhat tedious, because the multiply instructions are limited in what they can operate on. As an alternative you could break down the multiplication into shifts and adds, like:

add ah, ah ; ah*2
add al, ah ; al + 2*ah
shl ah, 2  ; 8*ah
add al, ah ; al + 10*ah

Note that the comments refer to the original values, and that this is a 8-bit version.

OTHER TIPS

This one is coded in assembly language using KEIL software for ARM model of 16 registers

   main 
       LDR R1,#0x07 
       LDR R2,#0x12
       LDR R3,#0x00
       ADD R3,R1,R2 
   END

where the contents of variables in R1 and R2 are added and stored in R3 i.e, R3 <--R1+R2.The value stored in R3 will be visible after debugging the whole code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top