Added mult example

This commit is contained in:
lcbcFoo 2017-11-12 18:40:25 -02:00
parent c90eacac55
commit 661fca19e1
5 changed files with 7 additions and 56 deletions

View file

@ -8,8 +8,6 @@
# Update the following variables to your environment
# to run example program
CROSS=/home/foo/IC/riscv-leon/rv32i/rv32i-gnu/bin/riscv32-unknown-elf-
DESIGN_DIR=../designs/leon3-digilent-nexys4ddr
#######################################################################
CC=gcc
AS=as
@ -29,7 +27,7 @@ OBJCPFLAGS=-O binary -j .text
# Note that target %.hex requeries %.S, not the makefile target %.s!
# They are different here because there are modifications needed
# on assembly code before running! (set stack, for example)
# More details on example.s
# More details on README
#
#################################################################
# Target .o

View file

@ -23,6 +23,10 @@ _start:
sw a0,-20(s0)
lw a5,-24(s0)
add a5,a5,1
# Move counter to x7
mv x7,a5
sw a5,-24(s0)
lw a4,-20(s0)
li a5,4096
@ -34,7 +38,7 @@ _start:
add sp,sp,32
###########################
# Move result to x6, since we dont have printf yet =(
# Move i to x6, since we dont have printf yet =(
mv x6,a4
# Stop processor
sbreak

BIN
riscv/main.bin Normal file

Binary file not shown.

View file

@ -4,8 +4,7 @@ void _start(){
int i = 1;
int count = 0;
// Multiplies i by 4 while i < 4
// Read commentaries on main.s
// Multiplies i by 4
do{
i = mul(i,4);
count++;

View file

@ -1,50 +0,0 @@
/* Author: Lucas Castro
* Date: 10/09/2017
*
* Reads a binary file and converts its content to readable hexadecimal
*/
#include <stdio.h>
#include <stdint.h>
int main(int argc, char** argv){
char word;
char res[8];
uint8_t i = 0;
FILE* input;
FILE* output;
if(argc != 3){
printf("Usage: ./<program name> <input bin file> <output readable hex file>\n");
return 1;
}
input = fopen(argv[1], "rb");
output = fopen(argv[2], "w");
if(input == NULL){
printf("Error opening input!\n");
return 1;
}
if(output == NULL){
fclose(input);
printf("Error opening output!\n");
return 1;
}
while(fread(&word, sizeof(unsigned char), 1, input)){
sprintf(res, "%02X", (unsigned char) word & 0xff);
fwrite(&res, sizeof(unsigned char), 2, output);
i++;
if(i == 4){
fwrite("\n", sizeof(char), 1, output);
i = 0;
}
}
fclose(input);
fclose(output);
return 0;
}