I'm implementing a code in IAS assembly that solve this problem:
I have an array of integers A=[a1,a2,...,an]
and I have to calculate B=[|log2 a1|,|log2 a2|,...,|log2 an|]
, where ||
is the floor function that rounds down to the nearest integer.
I'm trying to implement the following steps:
- create first the
|log2 x|
and verify that it works for a positive integer - run 1) in each number of the array A to calculate the array B
I wrote this, but it doesn't work:
loop: S(x)->Ac+ n ;load n in AC
Cc->S(x) log ;if AC >= 0 jump to log
halt ; else end the program
.empty
log: S(x)->R resm ;copy number 2 to AR
S(x)*R->A two ;multiply 2*2
At->S(x) resm ;save in resm
S(x)->Ah+ one ;+1 counter
At->S(x) cont ;save the counter
S(x)->Ac+ n ;load n in AC
S(x)->Ah- one;decrease n in 1
At->S(x) n ;save n
Cu->S(x) loop; jump to beggining to make all again
n: .data 4 ;number to calculate log
two: .data 2 ;base of the logarithm
one: .data 1 ;for increase the counter
resm: .data 2 ;for save the result of the multiplication
cont: .data 0 ;save the result of the logarithm
IAS is a teaching teaching language, implemented in a simulator. That page also documents the instruction set.