Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .extern fread, fwrite
- .data
- temp:
- .byte 0
- .text
- .globl readbyte
- # Navn: readbyte
- # Synopsis: Leser en byte fra en binærfil.
- # C-signatur: int readbyte (FILE *f)
- # Registre: Låser %edx under kjøring ved å pushe den på stakken
- # da %edx benyttes i readutf8char til å lagre midlertidige verdier.
- readbyte:
- pushl %ebp
- pushl %edx
- movl %esp,%ebp
- pushl 12(%ebp)
- pushl $1
- pushl $1
- leal temp,%ecx
- pushl %ecx
- call fread
- movl %ebp, %esp
- cmp $0, %eax
- je rb_0
- movl temp,%eax
- jmp rb_x
- rb_0:
- movl $-1,%eax
- rb_x:
- popl %edx
- popl %ebp
- ret
- .globl readutf8char
- # Navn: readutf8char
- # Synopsis: Leser et Unicode-tegn fra en binærfil.
- # C-signatur: long readutf8char (FILE *f)
- # Registre:
- readutf8char:
- pushl %ebp
- movl %esp,%ebp
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- cmp $0x7F,%eax
- jle ru8_x
- cmp $0xDF,%eax
- jbe read2
- cmp $0xEF,%eax
- jbe read3
- cmp $0xF7,%eax
- jbe read4
- read2:
- movl %eax,%edx
- and $0x1F,%edx
- shll $6,%edx
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- and $0x3F,%eax
- or %edx,%eax
- jmp ru8_x
- read3:
- movl %eax,%edx
- and $0x0F,%edx
- shll $6,%edx
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- and $0x3F,%eax
- or %eax,%edx
- shll $6,%edx
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- and $0x3F,%eax
- or %edx,%eax
- jmp ru8_x
- read4:
- movl %eax,%edx
- and $0x07,%edx
- shll $6,%edx
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- and $0x3F,%eax
- or %eax,%edx
- shll $6,%edx
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- and $0x3F,%eax
- or %eax,%edx
- shll $6,%edx
- pushl 8(%ebp)
- call readbyte
- movl %ebp, %esp
- and $0x3F,%eax
- or %edx,%eax
- ru8_x:
- popl %ebp
- ret
- .globl writebyte
- # Navn: writebyte
- # Synopsis: Skriver en byte til en binærfil.
- # C-signatur: void writebyte (FILE *f, unsigned char b)
- # Registre:
- writebyte:
- pushl %ebp
- movl %esp,%ebp
- pushl 8(%ebp)
- pushl $1
- pushl $1
- leal 12(%ebp),%eax
- pushl %eax
- call fwrite
- movl %ebp, %esp
- popl %ebp
- ret
- .globl writeutf8char
- # Navn: writeutf8char
- # Synopsis: Skriver et tegn kodet som UTF-8 til en binærfil.
- # C-signatur: void writeutf8char (FILE *f, unsigned long u)
- # Registre:
- writeutf8char:
- pushl %ebp
- movl %esp,%ebp
- movl 12(%ebp),%eax
- cmp $0x7F, %eax
- jbe write1
- cmp $0x07FF, %eax
- jbe write2
- cmp $0xFFFF, %eax
- jbe write3
- cmp $0x1FFFFF, %eax
- jbe write4
- write1:
- pushl 12(%ebp)
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- jmp wu8_x
- write2:
- shrl $6,%eax
- and $0x1F, %eax
- or $0xC0, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- movl 12(%ebp),%eax
- and $0x3F, %eax
- or $0x80, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- jmp wu8_x
- write3:
- shrl $12,%eax
- and $0x0F,%eax
- or $0xE0,%eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- movl 12(%ebp),%eax
- shrl $6,%eax
- and $0x3F, %eax
- or $0x80, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- movl 12(%ebp),%eax
- and $0x3F, %eax
- or $0x80, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- jmp wu8_x
- write4:
- shrl $18,%eax
- and $0x07,%eax
- or $0xF0,%eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- movl 12(%ebp),%eax
- shrl $12,%eax
- and $0x3F, %eax
- or $0x80, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- movl 12(%ebp),%eax
- shrl $6,%eax
- and $0x3F, %eax
- or $0x80, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- movl 12(%ebp),%eax
- and $0x3F, %eax
- or $0x80, %eax
- pushl %eax
- pushl 8(%ebp)
- call writebyte
- movl %ebp, %esp
- wu8_x: popl %ebp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement