#12 Jerry
Mozna to jen beres moc doslovne, mohl java kod pouzit jako formu pseudokodu (funkcni). Pochybuju ze by nekdo pri smyslech chtel rucni preklad do java byte kodu :)
No kazdopadne nejrychlejsi je to proste prelozit z C do asm
#include <stdint.h>
#include <stdio.h>
long hamming(long va[], long vb[], size_t length) {
long hd = 0;
for (size_t i = 0; i < length; i++) {
if (va[i] != vb[i]) {
hd++;
}
}
return hd;
}
int main() {
long a[] = {1, 0, 0, 1, 0};
long b[] = {1, 1, 0, 1, 1};
long out = hamming(a, b, sizeof(a)/sizeof(*a));
printf("%li", out);
}
Coz se prelozi na (je tam trochu vic veci nez je skutecne potreba):
.text
.globl hamming
.type hamming, @function
hamming:
.LFB0:
.cfi_startproc
push rbp #
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp #,
.cfi_def_cfa_register 6
mov QWORD PTR [rbp-24], rdi # va, va
mov QWORD PTR [rbp-32], rsi # vb, vb
mov QWORD PTR [rbp-40], rdx # length, length
mov QWORD PTR [rbp-16], 0 # hd,
mov QWORD PTR [rbp-8], 0 # i,
jmp .L2 #
.L4:
mov rax, QWORD PTR [rbp-8] # tmp95, i
lea rdx, [0+rax*8] # D.2341,
mov rax, QWORD PTR [rbp-24] # tmp96, va
add rax, rdx # D.2342, D.2341
mov rdx, QWORD PTR [rax] # D.2343, *_9
mov rax, QWORD PTR [rbp-8] # tmp97, i
lea rcx, [0+rax*8] # D.2341,
mov rax, QWORD PTR [rbp-32] # tmp98, vb
add rax, rcx # D.2342, D.2341
mov rax, QWORD PTR [rax] # D.2343, *_14
cmp rdx, rax # D.2343, D.2343
je .L3 #,
add QWORD PTR [rbp-16], 1 # hd,
.L3:
add QWORD PTR [rbp-8], 1 # i,
.L2:
mov rax, QWORD PTR [rbp-8] # tmp99, i
cmp rax, QWORD PTR [rbp-40] # tmp99, length
jb .L4 #,
mov rax, QWORD PTR [rbp-16] # D.2343, hd
pop rbp #
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size hamming, .-hamming
.section .rodata
.LC0:
.string "%li"
.text
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
push rbp #
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp #,
.cfi_def_cfa_register 6
sub rsp, 112 #,
mov QWORD PTR [rbp-96], 1 # a,
mov QWORD PTR [rbp-88], 0 # a,
mov QWORD PTR [rbp-80], 0 # a,
mov QWORD PTR [rbp-72], 1 # a,
mov QWORD PTR [rbp-64], 0 # a,
mov QWORD PTR [rbp-48], 1 # b,
mov QWORD PTR [rbp-40], 1 # b,
mov QWORD PTR [rbp-32], 0 # b,
mov QWORD PTR [rbp-24], 1 # b,
mov QWORD PTR [rbp-16], 1 # b,
lea rcx, [rbp-48] # tmp89,
lea rax, [rbp-96] # tmp90,
mov edx, 5 #,
mov rsi, rcx #, tmp89
mov rdi, rax #, tmp90
call hamming #
mov QWORD PTR [rbp-104], rax # out, tmp91
mov rax, QWORD PTR [rbp-104] # tmp92, out
mov rsi, rax #, tmp92
mov edi, OFFSET FLAT:.LC0 #,
mov eax, 0 #,
call printf #
mov eax, 0 # D.2344,
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Ubuntu 5.5.0-12ubuntu1~14.04) 5.5.0 20171010"
.section .note.GNU-stack,"",@progbits
Takze se z toho da neco malo vykrast