Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. ## Program 1 Paul Totzke
  2.  
  3. ##
  4.  
  5. ##This program creates a visual in the mips lanuage of a tree
  6.  
  7. ##
  8.  
  9.  
  10.  
  11.  
  12.  
  13. ##################################################
  14.  
  15. # #
  16.  
  17. # text segment #
  18.  
  19. # #
  20.  
  21. ##################################################
  22.  
  23.  
  24.  
  25. .text
  26.  
  27. __start:
  28.  
  29.  
  30.  
  31. #
  32.  
  33. # load variables into registers
  34.  
  35. # takes "Number of Lines?" and puts int into $t0
  36.  
  37. #
  38.  
  39.  
  40.  
  41. li $v0 1
  42. li $v1 17
  43.  
  44. la $a0 s1
  45.  
  46. syscall
  47.  
  48.  
  49. li $v0 4
  50.  
  51. syscall
  52.  
  53.  
  54. move $t0 $v0
  55.  
  56. ## used as my i value in my __maketree for loop
  57.  
  58. li $t1 0
  59.  
  60.  
  61. la $t1 n
  62.  
  63. sw $s0 0($t1)
  64.  
  65. add $t0 $t0 -2
  66.  
  67.  
  68. la $t1 x
  69.  
  70. sw $s1 0($t1)
  71.  
  72.  
  73. la $s2 i
  74.  
  75. sw $t1 0($s2)
  76.  
  77. li $t0 -1
  78.  
  79.  
  80. la $t2 temp
  81.  
  82. sw $t0 0($t2)
  83.  
  84.  
  85. la $a1 x
  86.  
  87. lw $t0 0($a1)
  88.  
  89. li $t1 0
  90.  
  91. li $t2 13
  92.  
  93. ## checks if number is between 1 and 16
  94.  
  95. blt $t0 $t1 __exit
  96.  
  97. bgt $t0 $t2 __exit
  98.  
  99.  
  100.  
  101. __maketree:
  102.  
  103. la $t0 temp
  104.  
  105. lw $t0 0($t0)
  106.  
  107.  
  108. la $t1 x
  109.  
  110. lw $t1 0($t0)
  111.  
  112. add $t0 $t0 1
  113.  
  114.  
  115. la $t0 temp
  116.  
  117. sw $t0 0($t0)
  118.  
  119. bge $t0 $t1 endmaketree
  120.  
  121. li $t0 1 ##RESETS the loop counter
  122.  
  123.  
  124. la $t0 i
  125.  
  126. sw $t0 0($t0)
  127.  
  128. ##for(int i = 1; i<(numberOfLines-numberPrinted) ; i++)
  129.  
  130. b eval
  131.  
  132.  
  133. body:
  134.  
  135. li $v0 1
  136.  
  137. la $a0 space
  138. li $a1 1
  139.  
  140. syscall
  141.  
  142.  
  143. la $t0 i
  144.  
  145. lw $t0 0($0)
  146.  
  147. add $t0 $t0 1
  148.  
  149.  
  150. la $t0 i
  151.  
  152. sw $t0 0($t0)
  153.  
  154.  
  155.  
  156. eval:
  157.  
  158. la $t0 i
  159.  
  160. lw $t0 0($t0)
  161.  
  162.  
  163. la $t1 x
  164.  
  165. lw $t1 0($t1)
  166.  
  167.  
  168. la $t2 temp
  169.  
  170. lw $t2 0($t2)
  171.  
  172. sub $t2 $t1 $t2
  173.  
  174. blt $t0 $t2 body
  175.  
  176. li $t0 0
  177.  
  178.  
  179. la $t0 i
  180.  
  181. sw $t0 0($t0)
  182.  
  183. ##for(int i = 1; i<(2*numberPrinted+1) ; i++)
  184.  
  185. b eval2
  186.  
  187.  
  188. body2:
  189.  
  190. li $v0 4
  191.  
  192. la $a0 star
  193.  
  194. la $a1 1
  195.  
  196. syscall
  197.  
  198.  
  199. la $t0 i
  200.  
  201. lw $t0 0($t0)
  202.  
  203. add $t0 $t0 1
  204.  
  205.  
  206. la $t1 i
  207.  
  208. sw $t0 0($t1)
  209.  
  210.  
  211.  
  212. eval2:
  213.  
  214. la $t0 i
  215.  
  216. lw $t0 0($t0)
  217.  
  218.  
  219. la $t1 temp
  220.  
  221. lw $t1 0($t1)
  222.  
  223. li $t2 2
  224.  
  225. mul $t1 $t1 $t2
  226.  
  227. add $t1 $t1 1
  228.  
  229. blt $t0 $t1 body2
  230.  
  231.  
  232. li $v0 1
  233.  
  234. la $a0 end1
  235.  
  236. la $a1 1
  237.  
  238. syscall
  239.  
  240. b __maketree
  241.  
  242.  
  243.  
  244. endmaketree:
  245.  
  246. ##prints the stem body 3 and 4 are identical this option was chosen for convience instead of a loop for it.
  247.  
  248. ###RESETS the loop counter
  249.  
  250. li $t0 1
  251.  
  252.  
  253. la $t1 i
  254.  
  255. sw $t0 0($t1)
  256.  
  257. b eval3
  258.  
  259.  
  260. body3:
  261.  
  262. ##prints " "
  263. la $a0 space
  264.  
  265. li $a1 1
  266.  
  267. li $v0 1
  268.  
  269. syscall
  270.  
  271.  
  272. la $t0 i
  273.  
  274. lw $t0 0($t0)
  275.  
  276. add $t0 $t0 1
  277.  
  278.  
  279. la $t0 i
  280.  
  281. sw $t0 0($t0)
  282.  
  283.  
  284.  
  285. eval3:
  286.  
  287. la $t0 i
  288.  
  289. lw $t0 0($t0)
  290.  
  291.  
  292. la $t1 x
  293.  
  294. lw $t1 0($t1)
  295.  
  296. blt $t0 $t1 body3
  297.  
  298.  
  299. la $a0 star
  300.  
  301. li $a1 1
  302.  
  303. li $v0 1
  304.  
  305. syscall
  306.  
  307.  
  308. ##prints "*\n"
  309.  
  310. la $a0 end1
  311.  
  312. li $a1 1
  313.  
  314. li $v0 1
  315.  
  316. syscall
  317.  
  318.  
  319. ##RESETS the loop counter
  320.  
  321. li $t1 1
  322.  
  323.  
  324. la $t0 i
  325.  
  326. sw $t0 0($t0)
  327.  
  328. b eval4
  329.  
  330.  
  331. body4:
  332.  
  333. ##prints " "
  334. la $a0 space
  335. la $a1 1
  336.  
  337. li $v0 1
  338.  
  339. syscall
  340.  
  341.  
  342. la $t0 i
  343.  
  344. lw $t0 0($t0)
  345.  
  346. add $t0 $t0 1
  347.  
  348.  
  349. la $t1 i
  350.  
  351. sw $t0 0($t1)
  352.  
  353.  
  354. eval4:
  355.  
  356. la $t0 i
  357.  
  358. lw $t0 0($t0)
  359.  
  360.  
  361. la $t1 x
  362.  
  363. lw $t1 0($t1)
  364.  
  365. blt $t0 $t1 body4
  366.  
  367.  
  368. ##prints "*\n"
  369.  
  370. la $a0 star
  371.  
  372. la $a1 1
  373.  
  374. li $v0 1
  375.  
  376. syscall
  377.  
  378.  
  379. la $a0 end1
  380.  
  381. la $a1 1
  382.  
  383. li $v0 1
  384.  
  385. syscall
  386.  
  387.  
  388.  
  389.  
  390.  
  391. #
  392.  
  393. # exit();
  394.  
  395. #
  396.  
  397. __exit:
  398.  
  399. #call exit
  400.  
  401. li $v0 0
  402.  
  403. syscall
  404.  
  405.  
  406.  
  407.  
  408.  
  409. ##################################################
  410.  
  411. # #
  412.  
  413. # data segment #
  414.  
  415. # #
  416.  
  417. ##################################################
  418.  
  419.  
  420.  
  421. .data
  422.  
  423. #
  424.  
  425. # memory variables
  426.  
  427. # (C++ analogy: int s1)
  428.  
  429. #
  430.  
  431. s1: .asciiz "Number of Lines? "
  432.  
  433. star: .asciiz "*"
  434.  
  435. space: .asciiz " "
  436.  
  437. end1: .asciiz "\n"
  438.  
  439. x: .space 1
  440.  
  441. i: .space 1
  442.  
  443. n: .space 1
  444.  
  445. temp: .space 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement