Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .extern fread, fwrite
  2.  
  3.     .data
  4. temp:
  5.     .byte 0
  6.  
  7.     .text
  8.     .globl  readbyte
  9.  # Navn:    readbyte
  10.  # Synopsis:    Leser en byte fra en binærfil.
  11.  # C-signatur:  int readbyte (FILE *f)
  12.  # Registre:    Låser %edx under kjøring ved å pushe den på stakken
  13.  #      da %edx benyttes i readutf8char til å lagre midlertidige verdier.
  14.  
  15. readbyte:
  16.     pushl   %ebp   
  17.     pushl   %edx
  18.     movl    %esp,%ebp
  19.    
  20.     pushl   12(%ebp)
  21.     pushl   $1
  22.     pushl   $1
  23.     leal    temp,%ecx
  24.     pushl   %ecx
  25.  
  26.     call fread
  27.     movl    %ebp, %esp
  28.    
  29.     cmp $0, %eax
  30.     je  rb_0
  31.    
  32.     movl    temp,%eax
  33.     jmp rb_x
  34.  
  35. rb_0:  
  36.     movl    $-1,%eax
  37.  
  38. rb_x:  
  39.     popl    %edx
  40.     popl    %ebp       
  41.     ret        
  42.  
  43.     .globl  readutf8char
  44.  # Navn:    readutf8char
  45.  # Synopsis:    Leser et Unicode-tegn fra en binærfil.
  46.  # C-signatur:  long readutf8char (FILE *f)
  47.  # Registre:
  48.    
  49. readutf8char:
  50.     pushl   %ebp       
  51.     movl    %esp,%ebp  
  52.  
  53.     pushl   8(%ebp)
  54.    
  55.     call    readbyte
  56.    
  57.     movl    %ebp, %esp
  58.    
  59.     cmp $0x7F,%eax
  60.     jle ru8_x
  61.  
  62.     cmp $0xDF,%eax
  63.     jbe read2
  64.  
  65.     cmp $0xEF,%eax
  66.     jbe read3
  67.  
  68.     cmp $0xF7,%eax
  69.     jbe read4
  70.  
  71.  
  72. read2:
  73.     movl    %eax,%edx
  74.     and $0x1F,%edx
  75.     shll    $6,%edx
  76.  
  77.     pushl   8(%ebp)
  78.    
  79.     call    readbyte
  80.    
  81.     movl    %ebp, %esp
  82.  
  83.     and $0x3F,%eax
  84.     or  %edx,%eax
  85.     jmp ru8_x
  86.  
  87. read3:
  88.     movl    %eax,%edx
  89.     and $0x0F,%edx
  90.     shll    $6,%edx
  91.     pushl   8(%ebp)
  92.     call    readbyte
  93.     movl    %ebp, %esp
  94.     and $0x3F,%eax
  95.     or  %eax,%edx
  96.  
  97.     shll    $6,%edx
  98.     pushl   8(%ebp)
  99.     call    readbyte
  100.     movl    %ebp, %esp
  101.     and $0x3F,%eax
  102.     or  %edx,%eax
  103.  
  104.     jmp ru8_x
  105.  
  106. read4:
  107.     movl    %eax,%edx
  108.     and $0x07,%edx
  109.     shll    $6,%edx
  110.     pushl   8(%ebp)
  111.     call    readbyte   
  112.     movl    %ebp, %esp
  113.     and $0x3F,%eax
  114.     or  %eax,%edx
  115.  
  116.     shll    $6,%edx
  117.     pushl   8(%ebp)
  118.     call    readbyte   
  119.     movl    %ebp, %esp
  120.     and $0x3F,%eax
  121.     or  %eax,%edx
  122.  
  123.     shll    $6,%edx
  124.     pushl   8(%ebp)
  125.     call    readbyte
  126.     movl    %ebp, %esp
  127.     and $0x3F,%eax
  128.     or  %edx,%eax
  129.    
  130. ru8_x:
  131.     popl    %ebp       
  132.     ret        
  133.  
  134.     .globl  writebyte
  135.  # Navn:    writebyte
  136.  # Synopsis:    Skriver en byte til en binærfil.
  137.  # C-signatur:  void writebyte (FILE *f, unsigned char b)
  138.  # Registre:
  139.    
  140. writebyte:
  141.     pushl   %ebp       
  142.     movl    %esp,%ebp  
  143.    
  144.     pushl   8(%ebp)    
  145.     pushl   $1
  146.     pushl   $1
  147.     leal    12(%ebp),%eax
  148.     pushl   %eax       
  149.  
  150.     call fwrite
  151.  
  152.     movl    %ebp, %esp
  153.     popl    %ebp       
  154.     ret        
  155.  
  156.  
  157.     .globl  writeutf8char
  158.  # Navn:    writeutf8char
  159.  # Synopsis:    Skriver et tegn kodet som UTF-8 til en binærfil.
  160.  # C-signatur:  void writeutf8char (FILE *f, unsigned long u)
  161.  # Registre:
  162.    
  163. writeutf8char:
  164.     pushl   %ebp       
  165.     movl    %esp,%ebp  
  166.    
  167.     movl    12(%ebp),%eax  
  168.    
  169.     cmp $0x7F, %eax
  170.     jbe write1
  171.  
  172.     cmp $0x07FF, %eax
  173.     jbe write2
  174.  
  175.     cmp $0xFFFF, %eax
  176.     jbe write3
  177.  
  178.     cmp $0x1FFFFF, %eax
  179.     jbe write4
  180.    
  181. write1:
  182.     pushl   12(%ebp)
  183.     pushl   8(%ebp)
  184.     call    writebyte
  185.     movl    %ebp, %esp
  186.     jmp wu8_x
  187.  
  188. write2:
  189.     shrl    $6,%eax
  190.     and $0x1F, %eax
  191.     or  $0xC0, %eax
  192.     pushl   %eax
  193.     pushl   8(%ebp)
  194.     call    writebyte
  195.     movl    %ebp, %esp
  196.    
  197.     movl    12(%ebp),%eax
  198.     and $0x3F, %eax
  199.     or  $0x80, %eax
  200.     pushl   %eax
  201.     pushl   8(%ebp)
  202.     call    writebyte
  203.     movl    %ebp, %esp
  204.     jmp wu8_x
  205.  
  206. write3:
  207.     shrl    $12,%eax
  208.     and $0x0F,%eax
  209.     or  $0xE0,%eax
  210.     pushl   %eax
  211.     pushl   8(%ebp)
  212.     call    writebyte
  213.     movl    %ebp, %esp
  214.  
  215.     movl    12(%ebp),%eax
  216.     shrl    $6,%eax
  217.     and $0x3F, %eax
  218.     or  $0x80, %eax
  219.     pushl   %eax
  220.     pushl   8(%ebp)
  221.     call    writebyte
  222.     movl    %ebp, %esp
  223.    
  224.     movl    12(%ebp),%eax
  225.     and $0x3F, %eax
  226.     or  $0x80, %eax
  227.     pushl   %eax
  228.     pushl   8(%ebp)
  229.     call    writebyte
  230.     movl    %ebp, %esp
  231.     jmp wu8_x
  232.  
  233. write4:
  234.     shrl    $18,%eax
  235.     and $0x07,%eax
  236.     or  $0xF0,%eax
  237.     pushl   %eax
  238.     pushl   8(%ebp)
  239.     call    writebyte
  240.     movl    %ebp, %esp
  241.  
  242.     movl    12(%ebp),%eax
  243.     shrl    $12,%eax
  244.     and $0x3F, %eax
  245.     or  $0x80, %eax
  246.     pushl   %eax
  247.     pushl   8(%ebp)
  248.     call    writebyte
  249.     movl    %ebp, %esp
  250.  
  251.     movl    12(%ebp),%eax
  252.     shrl    $6,%eax
  253.     and $0x3F, %eax
  254.     or  $0x80, %eax
  255.     pushl   %eax
  256.     pushl   8(%ebp)
  257.     call    writebyte
  258.     movl    %ebp, %esp
  259.  
  260.     movl    12(%ebp),%eax
  261.     and $0x3F, %eax
  262.     or  $0x80, %eax
  263.     pushl   %eax
  264.     pushl   8(%ebp)
  265.     call    writebyte
  266.     movl    %ebp, %esp
  267.    
  268.  
  269. wu8_x:  popl    %ebp       
  270.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement