Advertisement
Jgug

LR2_2

May 22nd, 2014
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "m2560def.inc"
  2.  
  3. .def num1 = r25
  4. .def num2 = r23
  5. .def highreg = r24
  6. .def minusreg = r21
  7. .def temp1 = r22
  8.  
  9. .cseg
  10.    
  11. init:
  12.    
  13. main:
  14.     //addition
  15.     ldi num1,0x49
  16.     ldi r16,0x03
  17.     sts 0x0203,r16
  18.     ldi highreg,0x00
  19.    
  20.     lds num2,0x0203
  21.     mov temp1,num1
  22.    
  23.     add num1,num2
  24.     ldi r16,0x06
  25.     add num1,r16
  26.     brhc HFLAGCLEAR
  27.  
  28.     CHECKOVERFLOW:
  29.     add temp1,num2
  30.     ldi r16,0x76
  31.     add temp1,r16
  32.     brcs ADDHIGHREG
  33.    
  34.  
  35.     //subtraction
  36.     SUBTRACTION:
  37.     ldi num1,0x49
  38.     lds num2,0x0203
  39.  
  40.     mov temp1,num1
  41.  
  42.     sub num1,num2
  43.     brhs HFLAGSET
  44.  
  45.     CHECKMIMUS:
  46.     sub temp1,num2
  47.     brmi ADDMINUS
  48.  
  49.     rjmp main
  50.  
  51.  
  52.     ADDHIGHREG:
  53.         inc highreg
  54.         ldi r16,0x60
  55.         add num1,r16
  56.         rjmp SUBTRACTION
  57.  
  58.     HFLAGCLEAR:
  59.         subi num1,0x06
  60.         rjmp CHECKOVERFLOW
  61.        
  62.     HFLAGSET:
  63.         subi num1,0x06
  64.         rjmp CHECKMIMUS
  65.  
  66.     ADDMINUS:
  67.         bset 0
  68.         ror minusreg
  69.         rjmp main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement