This is a simple SystemVerilog question that I am having a surprisingly difficult time finding the answer for.
In this kind of bit array initialization syntax, is the b[0] part assigned to a's most significant bit, or the least significant bit?
bit a[7:0];
bit b[7:0] = 8'hff;
bit c[7:0] = 8'h00;
a = {b[0], c[6:0]};
So does a[0] == 1 or a[7] == 1?
The reason you've found it hard to find an answer is because the result is dependent on how you've declared things.
You've declared a to be [7:0]. Therefore the bits in a are arranged like this:
a7 a6 a5 a4 a3 a2 a1 a0
You then assign {b[0], c[6:0} to a:
a7 a6 a5 a4 a3 a2 a1 a0 = b0 c6 c5 c4 c3 c2 c1 c0
1 0 0 0 0 0 0 0 = 1 0 0 0 0 0 0 0
A[7] == 1
If you'd declared a to be [0:7] the result would have been:
a0 a1 a2 a3 a4 a5 a6 a7 = b0 c6 c5 c4 c3 c2 c1 c0
1 0 0 0 0 0 0 0 = 1 0 0 0 0 0 0 0
A[0] == 1
b[0] is assigned to the most significant bit, a[7]; i.e. a[7] == 1.
However, I'm not sure it's typo or your intention to use unpacked declaration. bit a[7:0] is an unpacked array, it does not mean continuous storage and it can not be directly assigned packed or integral value.
Following is adopted from SystemVerilog for Design, P.114, 5.3.1 Unpacked arrays
Unpacked array stores each element independently, but grouped under a common array name.
P.122, 5.3.5 Assigning values to arrays
SystemVerilog extends Verilog with two additional ways to assign values to unpacked arrays:
- The entire array can be assigned a list of values
- A slice of the array can be assigned a list of values.
The list of values is specified between '{ } braces, the same as with initializing unpacked arrays.
For packed array, bit [7:0] a, we do have correct answer from Paul.
Related
I'm trying to subtract two rows of different columns. Example table
C1
C2
C3
A1
2
A2
3
B1
4
So essentially, I want A2-A1 from C3 and C2 columns respectively. My approach was to somehow get values in C2New column and then subtract.
C1
C2
C2New
C3
C4
A1
2
2
A2
2
3
1
B1
4
If you are using explorer, here is how you can create the table:
let X = datatable( c1:string , c2:int , c3:int )
[ 'a1',2,3,
'a2', 0,3,
'b1', 0,4
];
X
| project c1, c2, c3
I have tried different joins, selfjoins, lookups and toscalar etc., expecting it would populate a value in empty cells and I would then create a new column or scalar with the difference in values. I'm totally new to coding and querying. Your help is appreciated.
KQL script:
let X = datatable( c1:string , c2:int , c3:int )
[ 'a1',2,3,
'a2', 0,3,
'b1', 0,4
];
X
| project c1, c2, c3
| serialize
| extend prevC2 = prev(c2,1)
| extend c4 = c3 - prevC2
Use Serialize operator to the table and then use prev function to get the previous row value.
Then subtract the c3 value from previous row c2 value.
Updated Script
As per David דודו Markovitz's comment, I updated script.
let X = datatable( c1:string , c2:int , c3:int )
[ 'a1',2,3,
'a2', 0,3,
'b1', 0,4
];
X| serialize c4 = c3 - prev(c2)
Output data
c1
c2
c3
prevc2
c4
a1
2
3
a2
0
3
2
1
b1
0
4
0
4
I need help with making some IF/OR/AND statements.
I have a cell (C8) that can be one of fourteen different variables. Depending on the value for C8 either cells F8, D8, or E8 will be used in three possible equations.
C D E F G H
7
8
9
C8 can equal any of the following values
0.5,0.55,0.6,0.7,0.75,1,1.0625,1.125,1.1875,1.25,1.325,1.375,1.4375,1.5
Equations needed:
IF C8 equals any values from 0.6 - 1.5 will then need to solve for (100-(F8-108)*5))+(G8+1))
IF C8 equals 0.5 will then need to solve for (100-((D8-56)*5)+(G8*1))
IF C8 equals 0.55 will then need to solve for (100-((E8-102)*5)+(G8*1)
I currently have this equation C8 if values are 0.6 1.5
=IF(AND(SUMPRODUCT(--ISNUMBER(SEARCH({0.6,0.65,0.7,0.75,1,1.0625,1.125,1.1875,1.25,1.325,1.375,1.4375,1.5},C8)))>0),100-(((F8-108)*5)+(G8*1)),"")
I think I need an IF/OR statement for two additional Situation
C8 equals 0.5 to solve for 100-(((D8-56)*5)+(G8*1))
C8 equals 0.55 to solve for 100-(((E8-102)*5)+(G8*1))
The following is the they type of IF/OR formulas I have tried.
=IF(OR(SUMPRODUCT(--ISNUMBER(SEARCH({0.6,0.65,0.7,0.75,1,1.0625,1.125,1.1875,1.25,1.325,1.375,1.4375,1.5},C8)))>0), 100-(((F8-108)*5)+(G8*1)), OR(ISNUMBER(SEARCH({0.5,C8)))>0)100-(((D8-56)*5)+(G8*1)), OR(ISNUMBER(SEARCH({0.55,C8))>0)100-(((E8-102*5)+(G8*1))"")
=IF(OR(SUMPRODUCT(--ISNUMBER(SEARCH({0.6,0.65,0.7,0.75,1,1.0625,1.125,1.1875,1.25,1.325,1.375,1.4375,1.5},C8)))>0), 100-(((F8-108)*5)+(G8*1)), (ISNUMBER(SEARCH({0.5,C8)))>0)100-(((D8-56)*5)+(G8*1)), (ISNUMBER(SEARCH({0.55,C8))>0)100-(((E8-102*5)+(G8*1))"")
Do you need to search for the values? If the cell can only equal one of the values you shared you can just build your statement around that assumption.
If that assumption is false, this will not work. [Equation3] will be called when C8 equals anything BUT .50 & .55 so C8 has to have limitations for this to work.
IF(C8 = .50, [Equation1], IF(C8 = .55, [Equation2], [Equation3]))
Where
[Equation1] = (100-((D8-56)*5)+(G8*1))
[Equation2] = (100-((E8-102)*5)+(G8*1)
[Equation3] = (100-(F8-108)*5))+(G8+1))
I want to check in Excel IF one value in one cell is lower in the following cells that comes after that cell. I have 54 cells with values. First I compare value in cell I1 with value in I2 to I54. If I find a value that is lower than I1 in cells I2 to I54 I want the text to be Check otherwise ok.
Then when I1 is done I want to check for cell I2 if there are any values in I3-I54 that is lower then I2. And so on to finaly check for I53 compared to just I54. I tried this
=IF(I1
Assuming your data looks something like this:
I
1 30
2 67
3 53
4 36
5 75
6 63
7 53
8 49
9 40
10 38
What I think you mean is that in I1 you want a formula that will tell you whether any of the below data (I2 - I54) is less than I1, if it is display "Check" otherwise display "Ok". You then want this to be the same in I2, but working out whether any of the data below I2 is less than the value in I2.
If this is correct then you could add a formula like the below in J1.
=IF(MIN(I2:$I$54)<I1,"Check","Ok")
By adding this in column J, you would end up with the following for the above data:
I J
1 30 Ok
2 67 Check
3 53 Check
4 36 Ok
5 75 Check
6 63 Check
7 53 Check
8 49 Check
9 40 Check
10 38 Ok
can anyone help me on this exercice on 68000 assembler please?
create a program that multiply two long words v1 and v3 unsigned. the product is number on 64 bits. the values v1 qnd v2 are respectively on the data registers D1 and D2 ?
thanks for your answers and sorry for my bad english
As long as you multiply unsigned 32-bit quantities, you can use the following way:
Theory: if your 32-bit quantities are A and B, split them like this:
A=Ah*0x10000+Al, B=Bh*0x10000+Bl, where each of Ah,Al,Bh,Bl is from 0 to 0xFFFF.
Then, obviously,
A * B = Ah * Bh<<32 + Al * Bh<<16 + Ah * Bl<<16 + Al * Bl
Each of these 4 multiplies is 16bit*16bit->32bit, thus perfectly fitting 68000 mulu.w command.
So the code:
;unsigned d0.l * d1.l -> d2.l:d3.l (d2.l holds high part)
move.w d0,d3
mulu.w d1,d3 ;d3.l is Al*Bl now
swap d0
swap d1
move.w d0,d2
mulu.w d1,d2 ;d2.l is Ah*Bh now
swap d0
move.w d0,d4
mulu.w d1,d4 ;d4 is Al*Bh
swap d4
moveq #0,d5
move.w d4,d5
clr.w d4 ; d5:d4 is 0x0000:Nh:Nl:0x0000, where N is Al*Bh
add.l d4,d3
addx.l d5,d2 ;add Al*Bh*0x10000 to the partial result in d2:d3
swap d0
swap d1
move.w d0,d4
mulu.w d1,d4 ;d4 is Ah*Bl
swap d4
moveq #0,d5
move.w d4,d5
clr.w d4 ; d5:d4 is 0x0000:Nh:Nl:0x0000, where N is Ah*Bl
add.l d4,d3
addx.l d5,d2 ;add Ah*Bl*0x10000 to the partial result
;d2:d3 is now the result
Of course, this code has many possibilities for optimization.
You have the problem that the MUL is only 16-bit, which means that if you have a 64-bit result, you need to do it in a sequence of 4 16-bit multiples and additions. You then return the result in two registers, as each register is 32-bits.
Assume you want A x B, and that A is AH and AL, with B as BH and BL
You get a series of partial products:
1: BL x AL
2: BL x AH x 2^16
3: BH x 2^16 x AL
4: BH x 2^16 x AH x 2^16
Each of the 4 partial products accumulate in their own section of the 64-bit word, and to make matters more interesting, you need to consider the carries.
What I will present is different from what you need as far as registers, but if you can understand it, you can change it for your exercise. Assume that A6 is the stack, and we’ll return the result in D0 for the high 32-bit word, and D1 for the low 32-bit word. Here’s a snippet of code from my library
umul32: link a6, #0
movem.l d2-d4, -(sp)
move.l (multiB,a6), d4 ;B into d4
move.l (multiA,a6), d3 ;A into d3
moveq #0,d2
moveq #0,d1
moveq #0,d0
mshift1: lsr.l #1,d4 ; look for 1 in multiplier
bcc.s mshift2 ; branch on 0
add.l d3,d1 ; add shifted A to product
addx.l d2,d0 ; add carry if found
mshift2: lsl.l #1,d3 ; shift for next iteration
roxl.l #1,d2
tst.l d4 ; check for 1s
bne.s mshift1
movem.l (sp)+,d2-d4
ulnk a6
move.l (sp),(8,sp) ;clean the 8 entries off the stack
addq.l 8, sp
rts
This is code generated by Amiga Aztec C compiler for multiplying two 32 bits integers :
D0/D1 : input
D0 : output
move.w d1,d2
mulu d0,d2
move.l d1,d3
swap d3
mulu d0,d3
swap d3
clr.w d3
add.l d3,d2
swap d0
mulu d1,d0
swap d0
clr.w d0
add.l d2,d0
rts
Im looking for a way to convert the file as below called INPUT to OUTPUT. The file INPUT consists of columns consisting the unique ID, ID and the value. I would like to convert the ID to separated IDs based on the value as distinction. I tried some basic commands but could not manage to make it work for the main input file which is 20,000 rows and has 15,000 IDs.
Does anyone has some nice ideas/suggestions how to handle this problem?
INPUT OUTPUT
unique ID VALUE unique ID VALUE
A1 GENEA 10 -> A1 GENEAp1 10
A2 GENEA 5 -> A2 GENEAp2 5
A3 GENEA 2 -> A3 GENEAp3 2
A4 GENEB 4 -> A4 GENEBp4 4
A5 GENEB 5 -> A5 GENEBp3 5
A6 GENEB 8 -> A6 GENEBp2 8
A7 GENEB 70 -> A7 GENEBp1 70
A8 GENEC 5 -> A8 GENECp1 5
A9 GENED 50 -> A9 GENEDp2 50
A10 GENED 10 -> A10 GENEDp3 10
Preferably the numbering of p based on the value. With p1 with the highest value, p2 second highest etc.
Here's a crazy one-liner that does it:
head -1 file; tail -n+2 file| nl| sort -nrk4| awk '{ ++m[$3]; print($1" "$2" "$3"p"m[$3]" "$4); }'| sort -n| cut -d' ' -f2-4| column -to' ';
Output:
unique ID VALUE
A1 GENEAp1 10
A2 GENEAp2 5
A3 GENEAp3 2
A4 GENEBp4 4
A5 GENEBp3 5
A6 GENEBp2 8
A7 GENEBp1 70
A8 GENECp1 5
A9 GENEDp1 50
A10 GENEDp2 10
It involves sorting the file by the VALUE column, and then processing it sequentially in awk, counting occurrences of each distinct ID in an associative array, so you can build up the p# count.
Additional notes:
I printed the header line (head -1) separately from the data lines (tail -n+2) so the main processing pipeline would only apply to the data lines.
I added a call to nl before the initial sort to capture the original line order in a new leading numbering column, and then sorted by that column afterward (and then cut out that numbering column) to return to the original order.
I added column -to' ' at the end to align the data lines, don't know if you want/need that. If you want to align the header line with the data lines, you can surround the head statement and main pipeline with a braced block and move the column -to' ' filter outside the braced block to align the whole thing.