avr.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. ;------------------------------------------------;
  2. ; Push/Pop register pair
  3. ;
  4. ; pushw Z
  5. .macro pushw
  6. push @0H
  7. push @0L
  8. .endm
  9. .macro popw
  10. pop @0L
  11. pop @0H
  12. .endm
  13. ;------------------------------------------------;
  14. ; Load/store word from/to direct memory/immediate
  15. ;
  16. ; ldsw Z,mem
  17. ; ldiw Z,imm
  18. .macro ldiw
  19. ldi @0L,low(@1)
  20. ldi @0H,high(@1)
  21. .endm
  22. .macro ldsw
  23. lds @0L,@1
  24. lds @0H,@1+1
  25. .endm
  26. .macro lddw
  27. ldd @0L,@1
  28. ldd @0H,@1+1
  29. .endm
  30. .macro stsw
  31. sts @0,@1L
  32. sts @0+1,@1H
  33. .endm
  34. .macro stdw
  35. std @0,@1L
  36. std @0+1,@1H
  37. .endm
  38. ;------------------------------------------------;
  39. ; Store immediate into indirect memory via r16
  40. ;
  41. ; sti Z,imm
  42. ; stdi Z+d,imm
  43. .macro sti
  44. ldi r16,@1
  45. st @0,r16
  46. .endm
  47. .macro stdi
  48. ldi r16,@1
  49. std @0,r16
  50. .endm
  51. ;------------------------------------------------;
  52. ; add/sub/subc/cp/cpc/lsl/lsr/rol/ror to register pair
  53. ;
  54. .macro addiw
  55. subi @0L,low(-(@1))
  56. sbci @0H,high(-(@1))
  57. .endm
  58. .macro subiw
  59. subi @0L,low(@1)
  60. sbci @0H,high(@1)
  61. .endm
  62. .macro addw
  63. add @0L,@1L
  64. adc @0H,@1H
  65. .endm
  66. .macro adcw
  67. adc @0L,@1L
  68. adc @0H,@1H
  69. .endm
  70. .macro subw
  71. sub @0L,@1L
  72. sbc @0H,@1H
  73. .endm
  74. .macro sbcw
  75. sbc @0L,@1L
  76. sbc @0H,@1H
  77. .endm
  78. .macro cpw
  79. cp @0L,@1L
  80. cpc @0H,@1H
  81. .endm
  82. .macro cpcw
  83. cpc @0L,@1L
  84. cpc @0H,@1H
  85. .endm
  86. .macro andw
  87. and @0L,@1L
  88. and @0H,@1H
  89. .endm
  90. .macro andiw
  91. andi @0L,low(@1)
  92. andi @0H,high(@1)
  93. .endm
  94. .macro orw
  95. or @0L,@1L
  96. or @0H,@1H
  97. .endm
  98. .macro oriw
  99. ori @0L,low(@1)
  100. ori @0H,high(@1)
  101. .endm
  102. .macro lslw
  103. lsl @0L
  104. rol @0H
  105. .endm
  106. .macro lsrw
  107. lsr @0H
  108. ror @0L
  109. .endm
  110. .macro rolw
  111. rol @0L
  112. rol @0H
  113. .endm
  114. .macro rorw
  115. ror @0H
  116. ror @0L
  117. .endm
  118. .macro clrw
  119. clr @0L
  120. clr @0H
  121. .endm
  122. .macro comw
  123. com @0L
  124. com @0H
  125. .endm
  126. .macro movew
  127. mov @0L, @1L
  128. mov @0H, @1H
  129. .endm
  130. ;------------------------------------------------;
  131. ; Store immediate into direct memory via r16
  132. ;
  133. ; stsi var,imm
  134. .macro stsi
  135. ldi r16,@1
  136. sts @0,r16
  137. .endm
  138. ;------------------------------------------------;
  139. ; Output port immediate via r16
  140. ;
  141. ; outi port,var
  142. .macro outi
  143. ldi r16,@1
  144. out @0,r16
  145. .endm
  146. ;------------------------------------------------;
  147. ; Add immediate to register
  148. .macro addi
  149. subi @0,-(@1)
  150. .endm
  151. ;------------------------------------------------;
  152. ; Long branch
  153. .macro rjne
  154. breq PC+2
  155. rjmp @0
  156. .endm
  157. .macro rjeq
  158. brne PC+2
  159. rjmp @0
  160. .endm
  161. .macro rjcc
  162. brcs PC+2
  163. rjmp @0
  164. .endm
  165. .macro rjcs
  166. brcc PC+2
  167. rjmp @0
  168. .endm
  169. .macro rjtc
  170. brts PC+2
  171. rjmp @0
  172. .endm
  173. .macro rjts
  174. brtc PC+2
  175. rjmp @0
  176. .endm
  177. .macro retcc
  178. brcs PC+2
  179. ret
  180. .endm
  181. .macro retcs
  182. brcc PC+2
  183. ret
  184. .endm
  185. .macro reteq
  186. brne PC+2
  187. ret
  188. .endm
  189. .macro retne
  190. breq PC+2
  191. ret
  192. .endm
  193. ;------------------------------------------------;
  194. ; Move single bit between two registers
  195. ;
  196. ; bmov dstreg,dstbit,srcreg.srcbit
  197. .macro bmov
  198. bst @2,@3
  199. bld @0,@1
  200. .endm