Created
January 21, 2023 17:38
-
-
Save angeloped/1f22bc43f2fbea920c8cc24c2fb5fd17 to your computer and use it in GitHub Desktop.
Memory Retrieval Operation | MHIP kernel component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
// Memory Retrieval Operation | MHIP kernel component | |
// 1/22/2023 | |
// 6 bit address/size | |
// A B C A B C | |
// 0 3 [ ] 1 3 [ ] | |
int SAM[] = {0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1}; | |
// ^ ^ ^ ^ ^ ^ | | |
// A - memory address | |
// B - data size | |
// C - the data | |
// binary to decimal | |
int BTD(int binary[], int bitsz){ | |
int decimal = 0; | |
for(int c=0; c<bitsz; c++){ | |
if(binary[c]){ | |
decimal += pow(2, bitsz-1-c); | |
} | |
} | |
return decimal; | |
} | |
int * slice(int arr[], int start, int bitsz){ | |
static int out[6]; | |
for(int i=0; i<bitsz; i++){ | |
out[i] = arr[start+i]; | |
} | |
return out; | |
} | |
void printd(int arr[], int bitsz){ | |
for(int i=0; i<bitsz; i++){ | |
printf("%d", arr[i]); | |
} | |
printf("\n"); | |
} | |
// hop process | |
void MEM_HOP(int address, int bitsz, int start, int final_){ | |
int position = start; | |
printf("\"MEMORY DATA\"\nADDR|SZ|DATA\n"); | |
while (position < final_){ | |
int MEM_ADDR = BTD( slice( SAM, position, bitsz ), bitsz ); //[python] BTD( SAM[position : position+bitsz], bitsz ); | |
int MEM_SIZE = BTD( slice( SAM, position+bitsz, (bitsz*2) ), bitsz ); //[python] BTD( SAM[position+bitsz : position+(bitsz*2)], bitsz ); | |
// keep until finding the address; retrieve data | |
if(MEM_ADDR==address){ | |
int *MEM_DATA = slice( SAM, position+(bitsz*2), (bitsz*2)+MEM_SIZE ); //[python] SAM[position+(bitsz*2) : position+(bitsz*2)+MEM_SIZE]; | |
printf("%d|%d|", MEM_ADDR, MEM_SIZE); | |
printd(MEM_DATA, MEM_SIZE); | |
break; | |
} | |
printf("%d|%d|", MEM_ADDR, MEM_SIZE); | |
position = position+(bitsz*2)+MEM_SIZE; | |
} | |
} | |
int main(){ | |
MEM_HOP(0x0, 6, 0, 30); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Memory Retrieval Operation | MHIP kernel component | |
# 1/23/2023 | |
# 6 bit address/size | |
# A B C A B C | |
# 0 3 [ ] 1 3 [ ] | |
SAM = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,1,1,1,0,1] | |
# ^ ^ ^ ^ ^ ^ | | |
# A - memory address | |
# B - data size | |
# C - the data | |
# binary to decimal | |
def BTD(binary, bitsz): | |
decimal = 0 | |
for c in range(0, bitsz): | |
if bool(binary[c]): | |
decimal += pow(2, bitsz-1-c) | |
return decimal | |
# hop process | |
def MEM_HOP(address, bitsz, start, final): | |
position = start | |
print("\"MEMORY DATA\"\nADDR|SZ|DATA") | |
while (position < final): | |
MEM_ADDR = BTD( SAM[position : position+bitsz], bitsz ) | |
MEM_SIZE = BTD( SAM[position+bitsz : position+(bitsz*2)], bitsz ) | |
# keep until finding the address; retrieve data | |
if MEM_ADDR==address: | |
MEM_DATA = SAM[position+(bitsz*2) : position+(bitsz*2)+MEM_SIZE] | |
print("{}|{}|{}".format(MEM_ADDR, MEM_SIZE, MEM_DATA)) | |
break | |
print("{}|{}".format(MEM_ADDR, MEM_SIZE)) | |
position = position+(bitsz*2)+MEM_SIZE | |
MEM_HOP(0x0, 6, 0, 30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment