diff --git a/week1/program1.bin b/week1/program1.bin new file mode 100644 index 00000000..45e3f53b Binary files /dev/null and b/week1/program1.bin differ diff --git a/week1/program1.s b/week1/program1.s new file mode 100644 index 00000000..935b35c3 --- /dev/null +++ b/week1/program1.s @@ -0,0 +1,27 @@ +#convert 32 bit value from Little Endian to Big endian format using RISC V assembly language + +.data +a: .word 0x12345678 +b: .word 0x00000000 + +.text +la x5,a +la x6,b + +lw x7,0(x5) +addi x28,x0,0x0ff + +and x18,x28,x7 +sb x18,3(x6) +srai x29,x7,8 + +and x19,x28,x29 +sb x19,2(x6) +srai x30,x29,8 + +and x20,x28,x30 +sb x20,1(x6) +srai x31,x30,8 + +and x21,x28,x31 +sb x21,0(x6) \ No newline at end of file diff --git a/week1/program1_5_stage.png b/week1/program1_5_stage.png new file mode 100644 index 00000000..9e48c5da Binary files /dev/null and b/week1/program1_5_stage.png differ diff --git a/week1/program1_single_stage.png b/week1/program1_single_stage.png new file mode 100644 index 00000000..ecda3acd Binary files /dev/null and b/week1/program1_single_stage.png differ diff --git a/week1/program2.bin b/week1/program2.bin new file mode 100644 index 00000000..b3c9e430 Binary files /dev/null and b/week1/program2.bin differ diff --git a/week1/program2.s b/week1/program2.s new file mode 100644 index 00000000..d67f9225 --- /dev/null +++ b/week1/program2.s @@ -0,0 +1,24 @@ +#Write an Assembly Program for addition of 2 64-bit numbers on RV32I + +.data +n1: .word 0x00000001,0x00000000 +n2: .word 0xffffffff,0x00000000 +n3: .word 0x00000000,0x00000000 + +.text +la x18,n1 +la x19,n2 +la x21,n3 + +lw x5,0(x18) +lw x6,0(x19) +lw x7,4(x18) +lw x8,4(x19) + +add x20,x5,x6 +sw x20,0(x21) +sltu x5,x20,x5 + +add x6,x7,x8 +add x6,x6,x5 +sw x6,4(x21) \ No newline at end of file diff --git a/week1/program2_5_stage.png b/week1/program2_5_stage.png new file mode 100644 index 00000000..87b87a57 Binary files /dev/null and b/week1/program2_5_stage.png differ diff --git a/week1/program2_single_stage.png b/week1/program2_single_stage.png new file mode 100644 index 00000000..d450c97b Binary files /dev/null and b/week1/program2_single_stage.png differ diff --git a/week2/program1.bin b/week2/program1.bin new file mode 100644 index 00000000..cb6aa151 Binary files /dev/null and b/week2/program1.bin differ diff --git a/week2/program1.s b/week2/program1.s new file mode 100644 index 00000000..be35c372 --- /dev/null +++ b/week2/program1.s @@ -0,0 +1,58 @@ +#Write an Assembly Program for:addition of N words,addition of N half words,addition of N bytes + +.data +n1: .word 0x00325462,0x12345678,0x00000004,0x10000000 +n2: .half 0x1234,0x5555,0x0003,0x0789 +n3: .byte 0x12,0x78,0x45,0x77 + +result_words: .word 0x0 # Result for words sum +result_halfwords: .word 0x0 # Result for half-words sum +result_bytes: .word 0x0 + +.text +la x5,n1 +la x6,n2 +la x7,n3 + +addi x28,x0,4 +addi x29,x0,4 +addi x30,x0,4 +addi x10,x0,4 + +sum_words_loop: + beq x28, x0, sum_words_done # If counter is zero, end loop + lw x18, 0(x5) # Load word from memory into x18 + add x10, x10, x18 # Add word to accumulator + addi x5, x5, 4 # Move to the next word (4 bytes) + addi x28, x28, -1 # Decrement counter + j sum_words_loop + +sum_words_done: + la x5, result_words # Load address for result_words + sw x10, 0(x5) # Store result of words sum + addi x10,x0,0 + +sum_halfwords_loop: + beq x29, x0, sum_halfwords_done + lh x19, 0(x6) # Load half-word from memory into x19 + add x10, x10, x19 # Add half-word to accumulator + addi x6, x6, 2 # Move to the next half-word (2 bytes) + addi x29, x29, -1 # Decrement counter + j sum_halfwords_loop # Repeat loop + +sum_halfwords_done: + la x6, result_halfwords # Load address for result_halfwords + sw x10, 0(x6) # Store result of half-words sum + addi x10,x0,0 + +sum_bytes_loop: + beq x30, x0, sum_bytes_done # If counter is zero, end loop + lb x20, 0(x7) # Load byte from memory into x20 + add x10, x10, x20 # Add byte to accumulator + addi x7, x7, 1 # Move to the next byte (1 byte) + addi x30, x30, -1 # Decrement counter + j sum_bytes_loop # Repeat loop + +sum_bytes_done: + la x7, result_bytes # Load address for result_bytes + sw x10, 0(x7) # Store result of bytes sum \ No newline at end of file diff --git a/week2/program1_5_stage.png b/week2/program1_5_stage.png new file mode 100644 index 00000000..3b15fa70 Binary files /dev/null and b/week2/program1_5_stage.png differ diff --git a/week2/program1_single_cycle.png b/week2/program1_single_cycle.png new file mode 100644 index 00000000..63de7416 Binary files /dev/null and b/week2/program1_single_cycle.png differ diff --git a/week2/program2.bin b/week2/program2.bin new file mode 100644 index 00000000..288348c2 Binary files /dev/null and b/week2/program2.bin differ diff --git a/week2/program2.s b/week2/program2.s new file mode 100644 index 00000000..a4d97895 --- /dev/null +++ b/week2/program2.s @@ -0,0 +1,36 @@ +#Write an Assembly program for calculating x = (y + m) - (L - D) + (Z + C) - D, where x, y, m, L, D, Z, C are elements of 32-bits wide + +.data +y: .word 0x12345678 +m: .word 0x11111111 +L: .word 0x23563952 +D: .word 0x08562314 +Z: .word 0x56132453 +C: .word 0x00000001 +x: .word 0x0 #initially assigned x to 0 + +.text +la x5,y +la x6,m +la x7,L +la x28,D +la x29,Z +la x30,C +la x31,x + +lw x18,0(x5) +lw x19,0(x6) +lw x20,0(x7) +lw x21,0(x28) +lw x22,0(x29) +lw x23,0(x30) + +add x18,x18,x19 +sub x20,x20,x21 +add x22,x22,x23 + +sub x18,x18,x20 +add x18,x18,x22 +sub x18,x18,x21 + +sw x18,0(x31) \ No newline at end of file diff --git a/week2/program2_5_stage.png b/week2/program2_5_stage.png new file mode 100644 index 00000000..4f149a3f Binary files /dev/null and b/week2/program2_5_stage.png differ diff --git a/week2/program2_single_cycle.png b/week2/program2_single_cycle.png new file mode 100644 index 00000000..96d32ceb Binary files /dev/null and b/week2/program2_single_cycle.png differ diff --git a/week3/program1.bin b/week3/program1.bin new file mode 100644 index 00000000..effe89b7 Binary files /dev/null and b/week3/program1.bin differ diff --git a/week3/program1.s b/week3/program1.s new file mode 100644 index 00000000..3e9a9afe --- /dev/null +++ b/week3/program1.s @@ -0,0 +1,30 @@ +#Write an assembly program to check if a number is a 2 out of 5 number + +.data +n: .byte 0x11,0x13 +a: .byte 0x0 + +.text +la x5,n +la x6,a + +#the MSB 3 bits of the byte number stored in memory must be zero +addi x7,x0,0x0e0 +addi x21,x0,0 +addi x23,x0,5 + +lb x28,0(x5) +and x29,x28,x7 + +bne x29,x0,exit +andi x30,x28,0x01f #x30 consists of the lower 5 bits +loop: + andi x20,x30,0x1 + srli x30,x30,1 + addi x23,x23,-1 + beq x0,x20,loop + addi x21,x21,1 #x21 counter of number of 1's + bne x23,x0,loop +exit: + sb x21,0(x6) + nop \ No newline at end of file diff --git a/week3/program1_5_stage.png b/week3/program1_5_stage.png new file mode 100644 index 00000000..a8024fd0 Binary files /dev/null and b/week3/program1_5_stage.png differ diff --git a/week3/program1_single_stage.png b/week3/program1_single_stage.png new file mode 100644 index 00000000..67f7ffbd Binary files /dev/null and b/week3/program1_single_stage.png differ diff --git a/week3/program2.bin b/week3/program2.bin new file mode 100644 index 00000000..3a6a461e Binary files /dev/null and b/week3/program2.bin differ diff --git a/week3/program2.s b/week3/program2.s new file mode 100644 index 00000000..f341fe35 --- /dev/null +++ b/week3/program2.s @@ -0,0 +1,41 @@ +#Write an assembly program to encode a number using Hamming code. + +.data +a: .byte 0x55 + +.text +la x9,a +lbu x10,0(x9) + +addi x11,x10,0 +srli x12,x11,1 #x12=d1 +srli x13,x11,2 #x13=d2 +srli x14,x11,3 #x14=d3 +srli x15,x11,4 #x15=d4 +srli x16,x11,5 #x16=d5 +srli x17,x11,6 #x15=d6 +srli x18,x11,7 #x18=d7 + +xor x11,x11,x12 #d0 xor d1 +xor x11,x11,x13 #xor with d3 +xor x11,x11,x14 #xor with d4 +xor x11,x11,x15 #xor with d6 +andi x20,x11,1 #c0 + +addi x21,x10,0 +xor x22,x21,x13 #d0 xor d2 +xor x22,x22,x14 #xor with d3 +xor x22,x22,x16 #xor with d5 +xor x22,x22,x17 #xor with d6 +andi x23,x22,1 #c1 + + +xor x25,x12,x13 #d1 xor d2 +xor x25,x25,x14 #xor with d3 +xor x25,x25,x18 #xor with d7 +andi x26,x25,1 #c2 + +xor x27,x15,x16 #d4 xor d5 +xor x27,x27,x17 #xor with x6 +xor x27,x27,x18 #xor with x7 +andi x28,x27,1 #c3 \ No newline at end of file diff --git a/week3/program2_5_stage.png b/week3/program2_5_stage.png new file mode 100644 index 00000000..82aa02b2 Binary files /dev/null and b/week3/program2_5_stage.png differ diff --git a/week3/program2_single_stage.png b/week3/program2_single_stage.png new file mode 100644 index 00000000..c9393c9d Binary files /dev/null and b/week3/program2_single_stage.png differ diff --git a/week4/program1.bin b/week4/program1.bin new file mode 100644 index 00000000..53898ed3 Binary files /dev/null and b/week4/program1.bin differ diff --git a/week4/program1.s b/week4/program1.s new file mode 100644 index 00000000..e6a69325 --- /dev/null +++ b/week4/program1.s @@ -0,0 +1,48 @@ +# Write an assembly program to find whether a given string is a palindrome or not, using stack operations + +.data +input: .asciz "racecar" # Input string +outputYn: .byte 0 # Output for palindrome or not + +.text + +la x18,input +la x19,outputYn + + +addi x25,x0,1 #for yes +addi x26,x0,0 #for no + +lb x6,0(x18) +lb x7,1(x18) +lb x28,2(x18) +lb x29,3(x18) +lb x30,4(x18) +lb x31,5(x18) +lb x5,6(x18) + +strcpy: + addi sp,sp,-4 + sw x25,0(sp) #To push the values in the stack + add x25,x0,x0 + +jal x1,func + +func: + bne x6,x5,exit + bne x7,x31,exit + bne x28,x30,exit + addi x25,x25,1 + sb x25,0(x19) + beq x0,x0,exit1 + + +L2: + lw x25,0(sp) + addi sp,sp,4 + jalr x0,x0,0 + +exit: + sb x26,0(x19) +exit1: + nop \ No newline at end of file diff --git a/week4/program1_5_stage.png b/week4/program1_5_stage.png new file mode 100644 index 00000000..15ad84db Binary files /dev/null and b/week4/program1_5_stage.png differ diff --git a/week4/program1_single_stage.png b/week4/program1_single_stage.png new file mode 100644 index 00000000..d2e237f6 Binary files /dev/null and b/week4/program1_single_stage.png differ diff --git a/week4/program2.bin b/week4/program2.bin new file mode 100644 index 00000000..3c1c5dd2 Binary files /dev/null and b/week4/program2.bin differ diff --git a/week4/program2.s b/week4/program2.s new file mode 100644 index 00000000..4d40ea97 --- /dev/null +++ b/week4/program2.s @@ -0,0 +1,26 @@ +## Write an assembly program to search a given number in an array + +.data +array: .word 0x01223113, 0x45362727,0x33434343,0x11211212 +search: .word 0x45362727 + +.text +la x10,array #address of array +la x11,search #address of the no to searched + +lw x16,0(x11) #no to be searched + +addi x20,x0,4 #no o loops +addi x27,x0,0 + +loop: lw x12,0(x10) #loading the values of the array + beq x12,x16,exit #checking if no is present in array + addi x27,x27,1 #incrementing the loop + beq x27,x20,exit2 #cheching for the loop iteration i<4 + addi x10,x10,4 #incrementing the array address + beq x0,x0,loop + + +exit: addi x25,x0,1 #if x25 is 1 the no is present + +exit2: nop \ No newline at end of file diff --git a/week4/program2_5_stage.png b/week4/program2_5_stage.png new file mode 100644 index 00000000..c06272c4 Binary files /dev/null and b/week4/program2_5_stage.png differ diff --git a/week4/program2_single_stage.png b/week4/program2_single_stage.png new file mode 100644 index 00000000..390dfb54 Binary files /dev/null and b/week4/program2_single_stage.png differ