Yuriy Nazarov
Love machine learning
In this article I try to talk about implementation part of CPU that can execute instructons subset of original AVR core. It’s only preview and can be use for academic using only. Because most useful programm that this CPU can execute is LED blinking :-) You can view this in following video:
Here right 8 LEDs indicate value of register R20. Left 8 LEDs – value of IP(PC). read more
I using nasm to generate object code from assembly source. 3 application required to compile executable:
– nasm
– gcc from gcc-
– ld from binutils package
*package names in ubuntu distribution
To install this packages run following command:
1 |
sudo apt-get install nasm binutils gcc-4.7-base |
Files contents:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
global func section .text func: push rbp mov rbp, rsp mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall pop rbp ret section .data message: db 'Hello, world!',0x0A ; message and newline length: equ $-message ; NASM definition pseudo-instruction |
1 2 3 4 5 6 |
void func(); //may be extern void func(); is more true way int main(){ func(); return 0; } |
1 2 3 |
nasm -f elf64 func.asm gcc -c use_asm.c gcc use_asm.o func.o -o use_asm |
And finaly:
1 2 |
$ ./use_asm Hello, world! |
I found some curiosity issues during finding optimal tool for compilation our program. Results of computations be different for different tools and different optimisation flags.
For investigating this issue I write simple code(full sources on github):
1 2 3 4 5 |
int i; long double res; for(i=0;i<100000000;i++){ res += cos(i); } |
In this small test program I can’t reproduce different results for different flags. But 5 different results for so similar programs is enough to demonstrate discovered effect.
Source code and tool | Result | Computation time, s |
Assembler | 1.53436944477410652787 | 3.81 |
gcc long | 1.53436944477462278158 | 4.4 |
gcc double | 1.53436944477389380914 | 4.4 |
icc long | 1.53436944477397574360 | 6.88 |
icc double | 1.53436944477334602510 | 1.50 |
p.s. also I found that manually written assembly code 15% faster than code on C in spite of using “-O2” optimisation flag.
Create local svn repository with name “my_local_repo”
1 |
$ svnadmin create my_local_repo |
prepare local repo
1 2 |
$ echo "#!/bin/sh" > hooks/pre-revprop-change $ chmod 755 hooks/pre-revprop-change |
initialize local copy
1 |
$ svnsync init file:///path/to/my_local_repo http://from.server/from_repo |
first run must be interactive to input and save your login and password
1 |
svnsync sync file:///path/to/my_local_repo |
write script to run it in cron
backup_svn_script.sh:
1 2 3 |
#!/bin/bash svnsync --non-interactive sync file:///path/to/my_local_repo tar -C /path/to/ -czf /path/to/backup/$(date +"svn_%Y_%m_%d_%H_%M_%S").tar.gz my_local_repo |
it produce files like “svn_2012_09_07_01_34_01.tar.gz” in your backup directory
Now you can add task to cron. Execute:
1 |
$ crontab -e |
and add following line to run backup at 4:00 (4 a.m.) every day
1 |
0 4 * * * /path/to/backup_svn_script.sh |
This method is not disk space efficient, but very simple.
Sources:
using svnsync
installing subversion server in ubuntu
web server on bash, nc, awk and sed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#!/bin/sh rm /tmp/f mkfifo /tmp/f #runloop while true do nc -l 8080 < /tmp/f | ( #read request read line #parse request args=$(echo -n "$line" | awk '{print $2}' | sed s~'?'~' '~ | awk '{print $2}') page=$(echo -n "$line" | awk '{print $2}' | sed s~'?'~' '~ | awk '{print $1}' | sed s~'/'~''~) user=$(echo -n "$args" | sed s~','~"\n"~ | sed s~'='~' '~ | awk '{if($1 == "user") print $2}') #some logic if [ "$page" != 'index.sh' ] then conttype="application/octet-stream" len=$(stat -c%s $page) echo "HTTP/1.0 200 OK" echo "Server: MadnessBASH" echo "Content-Length: $len" echo "Content-Type: $conttype" echo "" cat $page else conttype="text/html" if [ -z "$user" ] then data=`cat login.htm` else data=`cat index.htm` data=$(echo -n "$data" | sed s~_user_~"$user"~) fi len=`echo $data | wc -c` echo "HTTP/1.0 200 OK" echo "Server: MadnessBASH" echo "Content-Length: $len" echo "Content-Type: $conttype" echo "" echo $data fi ) > /tmp/f done |
How to get access to shell on the remote computer that don’t have “white”(“real” or “public”) IP without any additional software in linux?
Quick and dirty solution:
on server side:
1 2 3 4 |
mkfifo /tmp/p0.0 mkfifo /tmp/p0.1 screen sh -c 'cat < /tmp/p0.1 & cat > /tmp/p0.0' #now you can detach this from current console and attach it back when you want it |
on client side:
1 2 |
mkfifo /tmp/localpipe ssh -p 22 my.host.name 'cat < /tmp/p0.0 & cat > /tmp/p0.1' < /tmp/localpipe | bash > /tmp/localpipe |
pipe ‘/tmp/localpipe’ used to redirect bash output back to ssh
note: use exit command to stop redirection