mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-23 02:16:48 +08:00
added and documented example code
This commit is contained in:
parent
2614ef9ae4
commit
22cbb583b1
2 changed files with 71 additions and 11 deletions
|
|
@ -117,6 +117,8 @@ specified bits from the source. The `u` means don't consider the
|
||||||
sign bit as special. The `z` is what causes the zero fill first and
|
sign bit as special. The `z` is what causes the zero fill first and
|
||||||
sets it apart from `bfi`.
|
sets it apart from `bfi`.
|
||||||
|
|
||||||
|
See bottom for an example.
|
||||||
|
|
||||||
## `mvn`
|
## `mvn`
|
||||||
|
|
||||||
This instruction takes only takes two operands (but permits an optional
|
This instruction takes only takes two operands (but permits an optional
|
||||||
|
|
@ -147,6 +149,8 @@ That is, if your goal is to turn a positive integer into a negative
|
||||||
integer, use `neg`. If your goal is to negate bits for bit bashing
|
integer, use `neg`. If your goal is to negate bits for bit bashing
|
||||||
purposes, use `mvn`.*
|
purposes, use `mvn`.*
|
||||||
|
|
||||||
|
See bottom for an example.
|
||||||
|
|
||||||
## `lsl`
|
## `lsl`
|
||||||
|
|
||||||
**Logical Shift Left** moves bits to the left shifting 0 into any
|
**Logical Shift Left** moves bits to the left shifting 0 into any
|
||||||
|
|
@ -175,3 +179,40 @@ for bit bashing as it is how bits can be set to 1.
|
||||||
orr rd, rs, rm # rm is another register
|
orr rd, rs, rm # rm is another register
|
||||||
orr rd, rs, imm
|
orr rd, rs, imm
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
[Here](./ubfiz.s) is the code to an example:
|
||||||
|
|
||||||
|
```asm
|
||||||
|
.global main // 1
|
||||||
|
.text // 2
|
||||||
|
.align 2 // 3
|
||||||
|
/* This demo should be run from gdb. `layout regs` would be helpful. // 4
|
||||||
|
This demo shows: // 5
|
||||||
|
bfi - bit field insert // 6
|
||||||
|
*/ // 7
|
||||||
|
main: mov w1, wzr // // 8
|
||||||
|
mvn w1, w1 // set w1 to 0xFFFFFFFF // 9
|
||||||
|
mov w3, w1 // save for reuse // 10
|
||||||
|
mov w2, 3 // set bits 0 and 1 // 11
|
||||||
|
bfi w1, w2, 4, 4 // 12
|
||||||
|
// Look at w1. You will note that the bottom // 13
|
||||||
|
// 4 bits of w2 (0011) have been copied into the second // 14
|
||||||
|
// 4 bits of w1 including the zeros. // 15
|
||||||
|
// // 16
|
||||||
|
// NEXT DEMO // 17
|
||||||
|
mov w1, w3 // reset w1 // 18
|
||||||
|
mov w2, 3 // set bits 0 and 1 // 19
|
||||||
|
ubfiz w1, w2, 4, 2 // 20
|
||||||
|
// Look at w1. You will note that all the bits were // 21
|
||||||
|
// zeroed and then 2 bits from w2 are copied into w1 // 22
|
||||||
|
// starting at bit 4. Compare this to bfi. // 23
|
||||||
|
// // 24
|
||||||
|
// NEXT DEMO // 25
|
||||||
|
bfxil w3, w1, 4, 4 // 26
|
||||||
|
// Look at w3. You will note that 4 bits (0011) from // 27
|
||||||
|
// w1 were put into w3 starting at bit 0. // 28
|
||||||
|
mov w0, wzr // 29
|
||||||
|
ret // 30
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,30 @@
|
||||||
.global main
|
.global main
|
||||||
.text
|
.text
|
||||||
.align 2
|
.align 2
|
||||||
|
/* This demo should be run from gdb. `layout regs` would be helpful.
|
||||||
main: str x30, [sp, -16]!
|
This demo shows:
|
||||||
mov w1, 0xFF
|
bfi - bit field insert
|
||||||
mov w2, 0x0A
|
*/
|
||||||
ubfiz w1, w2, 0, 4
|
main: mov w1, wzr //
|
||||||
ldr x30, [sp], 16
|
mvn w1, w1 // set w1 to 0xFFFFFFFF
|
||||||
mov w0, wzr
|
mov w3, w1 // save for reuse
|
||||||
ret
|
mov w2, 3 // set bits 0 and 1
|
||||||
|
bfi w1, w2, 4, 4
|
||||||
|
// Look at w1. You will note that the bottom
|
||||||
|
// 4 bits of w2 (0011) have been copied into the second
|
||||||
|
// 4 bits of w1 including the zeros.
|
||||||
|
//
|
||||||
|
// NEXT DEMO
|
||||||
|
mov w1, w3 // reset w1
|
||||||
|
mov w2, 3 // set bits 0 and 1
|
||||||
|
ubfiz w1, w2, 4, 2
|
||||||
|
// Look at w1. You will note that all the bits were
|
||||||
|
// zeroed and then 2 bits from w2 are copied into w1
|
||||||
|
// starting at bit 4. Compare this to bfi.
|
||||||
|
//
|
||||||
|
// NEXT DEMO
|
||||||
|
bfxil w3, w1, 4, 4
|
||||||
|
// Look at w3. You will note that 4 bits (0011) from
|
||||||
|
// w1 were put into w3 starting at bit 0.
|
||||||
|
mov w0, wzr
|
||||||
|
ret
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue