Skip to content

Commit a874f80

Browse files
committed
Add Shr and Shl
Resolves #164.
1 parent fa068ca commit a874f80

3 files changed

Lines changed: 61 additions & 3 deletions

File tree

langs/a86/ast.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241
(instruct Xor (dst src) check:src-dest)
242242
(instruct Sal (dst i) check:shift)
243243
(instruct Sar (dst i) check:shift)
244+
(instruct Shl (dst i) check:shift)
245+
(instruct Shr (dst i) check:shift)
244246
(instruct Push (a1) check:push)
245247
(instruct Pop (a1) check:register)
246248
(instruct Pushf () check:none)

langs/a86/printer.rkt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@
120120
(string-append tab "sar "
121121
(arg->string a1) ", "
122122
(arg->string a2))]
123+
[(Shl a1 a2)
124+
(string-append tab "shl "
125+
(arg->string a1) ", "
126+
(arg->string a2))]
127+
[(Shr a1 a2)
128+
(string-append tab "shr "
129+
(arg->string a1) ", "
130+
(arg->string a2))]
123131
[(And a1 a2)
124132
(string-append tab "and "
125133
(arg->string a1) ", "

www/notes/a86.scrbl

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,8 @@ Each register plays the same role as in x86, so for example
16771677

16781678
@defstruct*[Sal ([dst register?] [i (integer-in 0 63)])]{
16791679
Shift @racket[dst] to the left @racket[i] bits and put result in @racket[dst].
1680-
The leftmost bits are discarded. Updates the conditional flags.
1680+
The most-significant (leftmost) bits are discarded. Updates the conditional
1681+
flags.
16811682

16821683
@#reader scribble/comment-reader
16831684
(ex
@@ -1693,8 +1694,9 @@ Each register plays the same role as in x86, so for example
16931694

16941695
@defstruct*[Sar ([dst register?] [i (integer-in 0 63)])]{
16951696
Shift @racket[dst] to the right @racket[i] bits and put result in @racket[dst].
1696-
The rightmost bits are discarded. The added leftmost bits are filled with the
1697-
sign bit of the original. Updates the conditional flags.
1697+
For each shift count, the least-significant (rightmost) bit is shifted into
1698+
the carry flag. The new most-significant (leftmost) bits are filled with the
1699+
sign bit of the original @racket[dst] value. Updates the conditional flags.
16981700

16991701
@#reader scribble/comment-reader
17001702
(ex
@@ -1713,6 +1715,52 @@ Each register plays the same role as in x86, so for example
17131715
(Mov 'rax #b100001101) ; #b100001101 = 269
17141716
(Sar 'rax 6)
17151717
(Ret))) ; #b100 = 4
1718+
1719+
(asm-interp
1720+
(prog
1721+
(Global 'entry)
1722+
(Label 'entry)
1723+
(Mov 'rax #b1000000000000000000000000000000000000000000000000000000000000000) ; 1 in MSB
1724+
(Sar 'rax 6)
1725+
(Ret))) ; #b1111111000000000000000000000000000000000000000000000000000000000
1726+
)
1727+
}
1728+
1729+
@defstruct*[Shl ([dst register?] [i (integer-in 0 63)])]{
1730+
Alias for @racket[Sal].
1731+
}
1732+
1733+
@defstruct*[Shr ([dst register?] [i (integer-in 0 63)])]{
1734+
Shift @racket[dst] to the right @racket[i] bits and put result in @racket[dst].
1735+
For each shift count, the least-significant (rightmost) bit is shifted into
1736+
the carry flag, and the most-significant bit is cleared. Updates the
1737+
conditional flags.
1738+
1739+
@#reader scribble/comment-reader
1740+
(ex
1741+
(asm-interp
1742+
(prog
1743+
(Global 'entry)
1744+
(Label 'entry)
1745+
(Mov 'rax #b100000000) ; #b100000000 = 256
1746+
(Shr 'rax 6)
1747+
(Ret))) ; #b100 = 4
1748+
1749+
(asm-interp
1750+
(prog
1751+
(Global 'entry)
1752+
(Label 'entry)
1753+
(Mov 'rax #b100001101) ; #b100001101 = 269
1754+
(Shr 'rax 6)
1755+
(Ret))) ; #b100 = 4
1756+
1757+
(asm-interp
1758+
(prog
1759+
(Global 'entry)
1760+
(Label 'entry)
1761+
(Mov 'rax #b1000000000000000000000000000000000000000000000000000000000000000) ; 1 in MSB
1762+
(Shr 'rax 6)
1763+
(Ret))) ; #b0000001000000000000000000000000000000000000000000000000000000000
17161764
)
17171765
}
17181766

0 commit comments

Comments
 (0)