Advertisement
Guest User

ej parcial assembly

a guest
Jun 10th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # largo 40
  3. # origen 36
  4. # destino 32
  5.  
  6. # SF_SIZE 32
  7.  
  8. ##STACKFRAME
  9.  
  10. ##SRA
  11.  
  12. # PADDING 28
  13. # RA 24
  14. # FP 20
  15. # GP 16
  16.  
  17. ## LTA
  18.  
  19. # PADDING  12
  20. # ITERADOR 8
  21. # HI 4
  22. # LO 0
  23.  
  24.  
  25.  
  26. .data
  27. hex_array:   .asciiz "0123456789abcdef"
  28.  
  29. .text
  30. .align 2
  31. .global hex_dump
  32. .ent hex_dump
  33.  
  34. hex_dump:
  35.  
  36.   .frame $fp,$fp,SF_SIZE
  37.   .set noreorder
  38.   cpload t9
  39.   .set reorder
  40.  
  41.   subu sp,sp, SF_SIZE
  42.   .cprestore GP
  43.  
  44.   sw $fp,FP(sp)
  45.   sw ra,RA(sp)
  46.   move $fp, sp
  47.  
  48.   ## FIN RECETA
  49.  
  50.   sw a0,destino($fp)
  51.   sw a1,origen($fp)
  52.   sw a2,largo($fp)
  53.  
  54.   li t0,0
  55.   sw t0,ITERADOR($fp)
  56.  
  57.   ## condicion de corte del loop
  58.   LOOP:
  59.   lw t0,ITERADOR($fp)
  60.   lw t1,largo($fp)
  61.   beq t0,t1,FIN_LOOP
  62.  
  63.   ## logica del loop
  64.  
  65.   ## me traigo el contenido del origen evaluado en el iterador (lo tengo en t0 el iterador, mala practica)
  66.  
  67.   lw t1,origen($fp)
  68.   addu t2,t0,t1 ## direccion de src[k]
  69.   lb t0,0(t2) ## me traigo el char
  70.   srl  t1,t0,4 ## src[k] >> 4
  71.  
  72.   sb t1,HI($fp)
  73.  
  74.   andi t3,t0,15 ## src[k] & 0xf
  75.   sb t3,LO($fp)
  76.  
  77.   la t0,hex_array
  78.   addu t1,t0,t3 ## t1 es la direccion de hex_array[lo]
  79.   sb t2,0(t1)  ## contenido de hex_array[lo]
  80.  
  81.   lw t0,destino($fp) ## traigo el puntero del destino
  82.   sb t2,0(t0) ## *dest= hex_array[lo]
  83.  
  84.   ## direccion destino ++
  85.   addiu t0,1
  86.   sw t0,destino($fp)
  87.  
  88.  
  89.   lw t3,HI($fp)
  90.   la t0,hex_array
  91.   addu t1,t0,t3 ## t1 es la direccion de hex_array[hi]
  92.   sb t2,0(t1)  ## contenid  o de hex_array[hi]
  93.  
  94.   lw t0,destino($fp) ## traigo el puntero del destino
  95.   sb t2,0(t0) ## *dest= hex_array[hi]
  96.  
  97.   ## direccion destino ++
  98.   addiu t0,1
  99.   sw t0,destino($fp)
  100.  
  101.   ## fin logica
  102.  
  103.  
  104.   ## iterador++
  105.   lw t0,ITERADOR($fp)
  106.   addiu t0,1
  107.   lw t0,ITERADOR($fp)
  108.  
  109.   b LOOP
  110.  
  111.   FIN_LOOP:
  112.  
  113.   lw t0,destino($fp)
  114.   move v0,t0
  115.  
  116.  .ent hex_dump
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement