Advertisement
Duoshot

a4

Nov 8th, 2013
2,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SPARK 3.85 KB | None | 0 0
  1.     include(macro_defs.m)
  2.  
  3.     define(FALSE,0)         !#define FALSE 0
  4.     define(TRUE,1)          !#define TRUE 1
  5.  
  6.     begin_struct(point)             !struct point
  7.     field(x,4)                     
  8.     field(y,4)
  9.     end_struct(point)
  10.  
  11.     begin_struct(dimension)         !struct dimension
  12.     field(width,4)
  13.     field(height,4)
  14.     end_struct(dimension)
  15.  
  16.     begin_struct(box)               !struct box
  17.     field(origin,align_of_point,size_of_point)
  18.     field(size,align_of_dimension,size_of_dimension)
  19.     field(area,4)
  20.     end_struct(box)
  21.  
  22.  
  23.     local_var
  24.     var(result,4)
  25.     var(first,align_of_box,size_of_box)
  26.     var(second,align_of_box,size_of_box)
  27.  
  28.  
  29. fma:    .asciz  "Initial box values:\n"
  30. fmb:    .asciz  "Changed box values:\n"
  31. fmc:    .asciz  "first"
  32. fmd:    .asciz  "second"
  33. string: .asciz  "Box %s origin = (%d,%d) width = %d height = %d"
  34. area:   .asciz  " area = %d\n"
  35.  
  36.     begin_main
  37.  
  38.     add     %fp, first, %o0
  39.     st      %o0, [%sp + struct_s]                      
  40.     call    newBox      
  41.     nop                          
  42.                    
  43.        
  44.     add     %fp, second, %o0  
  45.     st      %o0, [%sp + struct_s]                
  46.     call    newBox                                  
  47.     nop
  48.  
  49.     set     fma,    %o0
  50.     call    printf
  51.     nop
  52.  
  53.     set     fmc,    %o0
  54.     add     %fp,    first,  %o1
  55.     st      %o1,    [%sp+struct_s]
  56.     call    printBox
  57.     nop
  58.  
  59.     set     fmd,    %o0
  60.     add     %fp,    second, %o1
  61.     st      %o1,    [%sp+struct_s]
  62.     call    printBox
  63.     nop
  64.  
  65.     add     %fp,    first,  %o0
  66.     add     %fp,    second, %o1
  67.     call    equal
  68.     nop
  69.  
  70.     ld      [%sp+result],   %l0
  71.     cmp     %l0,    TRUE
  72.     bne     next
  73.     nop
  74.    
  75.     add     %fp,    first,  %o0
  76.     mov     -5,     %o1
  77.     mov     7,      %o2
  78.     call    move
  79.     nop
  80.  
  81.     add     %fp,    second, %o0
  82.     mov     3,      %o1
  83.     call    expand
  84.     nop
  85.    
  86. next:
  87.     set     fmb,    %o0
  88.     call    printf
  89.     nop
  90.  
  91.     set     fmc,    %o0
  92.     add     %fp,    first,  %o1
  93.     st      %o1,    [%sp+struct_s]
  94.     call    printBox
  95.     nop
  96.  
  97.     set     fmd,    %o0
  98.     add     %fp,    second, %o1
  99.     st      %o1,    [%sp+struct_s]
  100.     call    printBox
  101.     nop
  102.  
  103.     end_main
  104.  
  105. newBox: save    %sp,    (-92 + last_sym) & -8,  %sp
  106.  
  107.         ld      [%fp+struct_s], %o0
  108.         st      %g0,    [%o0+box_origin+point_x]
  109.         st      %g0,    [%o0+box_origin+point_y]
  110.  
  111.         mov     1,      %o1
  112.         st      %o1,    [%o0+box_size+dimension_width]
  113.         st      %o1,    [%o0+box_size+dimension_height]
  114.         st      %o1,    [%o0+box_area]
  115.  
  116.         ret
  117.         restore
  118.  
  119. move:   save    %sp,    (-92 + last_sym) & -8,  %sp
  120.  
  121.         ld      [%i0+box_origin+point_x],   %l0
  122.         ld      [%i0+box_origin+point_y],   %l1
  123.  
  124.         add     %l0,    %i1,    %l0
  125.         add     %l1,    %i2,    %l1
  126.  
  127.         st      %l0,    [%i0+box_origin+point_x]
  128.         st      %l1,    [%i0+box_origin+point_y]
  129.  
  130.         ret
  131.         restore
  132.  
  133. expand: save    %sp,    (-92+last_sym) & -8,    %sp
  134.  
  135.         ld  [%i0+box_size+dimension_width], %l0
  136.         ld  [%i0+box_size+dimension_height],    %l1
  137.  
  138.         smul    %l0,    %i1,    %l0
  139.         smul    %l1,    %i1,    %l1
  140.         smul    %l0,    %l1,    %l2
  141.  
  142.         st      %l0,    [%i0+box_size+dimension_width]
  143.         st      %l1,    [%i0+box_size+dimension_height]
  144.         st      %l2,    [%i0+box_area]
  145.  
  146.         ret
  147.         restore
  148.  
  149. printBox:   save    %sp,    (-92+last_sym) & -8,    %sp
  150.        
  151.         set     string, %o0
  152.         mov     %i0,    %o1
  153.         ld      [%fp+struct_s],     %l0
  154.         ld      [%l0+box_origin+point_x],   %o2
  155.         ld      [%l0+box_origin+point_y],   %o3
  156.         ld      [%l0+box_size+dimension_width], %o4
  157.         ld      [%l0+box_size+dimension_height],    %o5
  158.         call    printf
  159.         nop
  160.  
  161.         set     area,   %o0
  162.         ld      [%l0+box_area], %o1
  163.         call    printf
  164.         nop
  165.  
  166.         ret
  167.         restore
  168.  
  169. equal:  save    %sp,    (-92+last_sym) & -8,    %sp
  170.  
  171.         ld      [%fp+result],   %l2
  172.         mov     FALSE,          %l2
  173.         st      %l2,    [%fp+result]
  174.  
  175.         ld      [%i0+box_origin+point_x],   %l0
  176.         ld      [%i1+box_origin+point_x],   %l1
  177.         cmp     %l0,    %l1
  178.         bne     return
  179.         nop
  180.  
  181.         ld      [%i0+box_origin+point_y],   %l0
  182.         ld      [%i1+box_origin+point_y],   %l1
  183.         cmp     %l0,    %l1
  184.         bne     return
  185.         nop
  186.  
  187.         ld      [%i0+box_size+dimension_width], %l0
  188.         ld      [%i1+box_size+dimension_width], %l1
  189.         cmp     %l0,    %l1
  190.         bne     return
  191.         nop
  192.  
  193.         ld      [%i0+box_size+dimension_height],    %l0
  194.         ld      [%i1+box_size+dimension_height],    %l1
  195.         cmp     %l0,    %l1
  196.         bne     return
  197.         nop
  198.        
  199.         ld      [%fp+result],   %l2
  200.         mov     TRUE,           %l2
  201.         st      %l2,    [%fp+result]
  202.  
  203. return: ret
  204.         restore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement