From 8201b7c5473c0ac1e9cc0ac60df73dbecb84758e Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Fri, 26 Feb 2010 16:14:13 +0100 Subject: [PATCH] asma: erstes geruest --- asma/Makefile | 15 ++++++++++++++ asma/asma.s | 40 +++++++++++++++++++++++++++++++++++++ asma/asma_ref.s | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ asma/main.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100755 asma/Makefile create mode 100644 asma/asma.s create mode 100644 asma/asma_ref.s create mode 100644 asma/main.c diff --git a/asma/Makefile b/asma/Makefile new file mode 100755 index 0000000..0308c8b --- /dev/null +++ b/asma/Makefile @@ -0,0 +1,15 @@ +all: asma.o + +asma.o: asma.s + gcc -c -o asma.o asma.s + +.PHONY: clean +clean: + rm -f asma.o asma + +test1: all + gcc -pedantic -ansi -Wall -g -o asma asma.s main.c -D_GNU_SOURCE + +test2: + /usr/ftp/pub/ublu/test/asma/test + diff --git a/asma/asma.s b/asma/asma.s new file mode 100644 index 0000000..275e847 --- /dev/null +++ b/asma/asma.s @@ -0,0 +1,40 @@ + .file "asma.c" + .text +.globl asma + .type asma, @function +asma: +.LFB2: + movq %rdi, %rax + ret +.LFE2: + .size asma, .-asma + .section .eh_frame,"a",@progbits +.Lframe1: + .long .LECIE1-.LSCIE1 +.LSCIE1: + .long 0x0 + .byte 0x1 + .string "zR" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .uleb128 0x1 + .byte 0x3 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE1: +.LSFDE1: + .long .LEFDE1-.LASFDE1 +.LASFDE1: + .long .LASFDE1-.Lframe1 + .long .LFB2 + .long .LFE2-.LFB2 + .uleb128 0x0 + .align 8 +.LEFDE1: + .ident "GCC: (Debian 4.3.2-1.1) 4.3.2" + .section .note.GNU-stack,"",@progbits diff --git a/asma/asma_ref.s b/asma/asma_ref.s new file mode 100644 index 0000000..1480455 --- /dev/null +++ b/asma/asma_ref.s @@ -0,0 +1,52 @@ + .file "asma_ref.c" + .text +.globl asma_ref + .type asma_ref, @function +asma_ref: +.LFB2: + movl $0, %ecx +.L4: + movzbl (%rdi,%rcx), %edx + leal -65(%rdx), %eax + cmpb $26, %al + sbbl %eax, %eax + andl $32, %eax + addl %edx, %eax + movb %al, (%rdi,%rcx) + addq $1, %rcx + cmpq $16, %rcx + jne .L4 + movq %rdi, %rax + ret +.LFE2: + .size asma_ref, .-asma_ref + .section .eh_frame,"a",@progbits +.Lframe1: + .long .LECIE1-.LSCIE1 +.LSCIE1: + .long 0x0 + .byte 0x1 + .string "zR" + .uleb128 0x1 + .sleb128 -8 + .byte 0x10 + .uleb128 0x1 + .byte 0x3 + .byte 0xc + .uleb128 0x7 + .uleb128 0x8 + .byte 0x90 + .uleb128 0x1 + .align 8 +.LECIE1: +.LSFDE1: + .long .LEFDE1-.LASFDE1 +.LASFDE1: + .long .LASFDE1-.Lframe1 + .long .LFB2 + .long .LFE2-.LFB2 + .uleb128 0x0 + .align 8 +.LEFDE1: + .ident "GCC: (Debian 4.3.2-1.1) 4.3.2" + .section .note.GNU-stack,"",@progbits diff --git a/asma/main.c b/asma/main.c new file mode 100644 index 0000000..4c290ab --- /dev/null +++ b/asma/main.c @@ -0,0 +1,47 @@ +#include +#include +#include + +extern unsigned char *asma(unsigned char *s); + +unsigned char *asma_ref(unsigned char *s) +{ + int i; + for (i=0; i<16; i++) { + unsigned char c = s[i]; + c += (c >= 'A' && c <= 'Z') ? 'a'-'A' : 0; + s[i] = c; + } + return s; +} + +int main(int argc, char **argv) { + char *input1[]={"asdfABCDEFGHKL54", "foofuuMUHkk"}; + char *output1; + char *output2; + char *input2; + char *input3; + int i; + + for(i = 0; i < 2; i++) { + input2 = strdup(input1[i]); + input3 = strdup(input1[i]); + output1 = (unsigned char*) asma_ref((unsigned char *)(input2)); + output2 = (unsigned char*) asma((unsigned char *)(input3)); + + output1[16]='\0'; + output2[16]='\0'; + + if(memcmp(output1,output2, 16)) { + printf("Testfall falsch; erwartet:\n\t\"%s\"\ntatsaechliches Ergebnis:\n\t\"%s\"\n", output1, output2); + } else { + printf("Testfall \"%s\" passt.\n", output1); + } + + free(input2); + free(input3); + } + + return 0; +} + -- 2.25.1