0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[例題の為の例題]ダンプ入力を完成させよ!!!(オンラインコンパイラ)

Last updated at Posted at 2025-10-05

いろいろ注意

  • 過去ログを見よ!!!
  • m5stack で Z80 を 走らせたい(予定(間に合うか?(何の事?(無理やりやるか?
  • 実用に問題ないが処理の流れを変えた(終端文字の時は、ブレークで抜ける
  • いろいろ、昨日(20251006)、m5stackのイベントで、バタバタして、家に着いたのは、午前0時すぎだからな!!!(いろいろ、停滞(何の事?

プログラム



//0 1 2 3 4 5 6 7 8 9 A B C D E F
char t[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //00
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //10
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //20
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, //30

0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, //40
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //50
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //60
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //70

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //80
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //90
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //A0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //B0

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //C0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //D0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //E0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  //F0
};

#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    unsigned char p[]="01-02-0A";
    
    
    int i = 0; //カウンター
    int a; //一時領域
    int g; //一時領域
    
    printf("\"%s\"\n\n",p);
    
    while(1){  //無限ループ
    
        //読み飛ばし
        //構造化プログラミング先読み
        a = p[i]; //読み出し
    
        while((t[a] == 0) && (a != '0') && (a != 0)){
        
            printf("<%c>",a); //debug
            
            i++; 
            a = p[i]; //読み出し
       
        }  //while
    
        if(a == 0) break;  //終端文字の時は、ループを抜ける
    
    
        //16進の間
        //構造化プログラミング先読み
        a = p[i]; //読み出し
    
        g = 0;
        while( ((t[a] != 0) || (a == '0')) && (a != 0)){
        
            printf("[%c]",a); //debug
            
            g = (g << 4) + t[a];
       
            i++;
            a = p[i]; //読み出し
       
        }  //while
    
    
        if( p[i] == 0 ) {
            printf("(\\0)"); //debug
        } else {
            printf("(%c)",p[i]); //debug
        }
    
        printf("\n"); //debug
        
        printf("g = #%02X. (%d)\n",g,g);
    
        if(a == 0) break;  //終端文字の時は、ループを抜ける

    
    }  //while 0
    
}  //main



"01-02-0A"

[0][1](-)
g = #01. (1)
<->[0][2](-)
g = #02. (2)
<->[0][A](\0)
g = #0A. (10)



おまけ(関数化)




#include <iostream>
using namespace std;


//0 1 2 3 4 5 6 7 8 9 A B C D E F
char t[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //00
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //10
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //20
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, //30

0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, //40
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //50
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //60
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //70

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //80
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //90
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //A0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //B0

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //C0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //D0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //E0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  //F0
};

int dump_in(unsigned char *p,unsigned char *d){
    // Your code here!
    
    int i = 0; //カウンター 入力文字
    int l = 0; //カウンター 出力バイナリ
    int a; //一時領域
    int g; //一時領域
    
    printf("\"%s\"\n\n",p);
    
    while(1){  //無限ループ
    
        //読み飛ばし
        //構造化プログラミング先読み
        a = p[i]; //読み出し
    
        while((t[a] == 0) && (a != '0') && (a != 0)){
        
            printf("<%c>",a); //debug
            
            i++; 
            a = p[i]; //読み出し
       
        }  //while
    
        if(a == 0) break;  //終端文字の時は、ループを抜ける
    
    
        //16進の間
        //構造化プログラミング先読み
        a = p[i]; //読み出し
    
        g = 0;
        while( ((t[a] != 0) || (a == '0')) && (a != 0)){
        
            printf("[%c]",a); //debug
            
            g = (g << 4) + t[a];
       
            i++;
            a = p[i]; //読み出し
       
        }  //while
    
    
        if( p[i] == 0 ) {
            printf("(\\0)"); //debug
        } else {
            printf("(%c)",p[i]); //debug
        }
    
        printf("\n"); //debug
        
        printf("g = #%02X. (%d)\n",g,g); //debug
        
        d[l] = g;
        l++;
    
        if(a == 0) break;  //終端文字の時は、ループを抜ける

    
    }  //while 0
    
    return(l);
    
}  //main



int main(void){
    
    unsigned char p[]="01-02-0A";
   
        //メモリーエリアの確保
    unsigned char RAM[256] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

    int num = dump_in(p,RAM);
    
    printf("\n");
    printf("num:%d\n",num);
    printf("0:[%02X]\n",RAM[0]);
    printf("1:[%02X]\n",RAM[1]);
    printf("2:[%02X]\n",RAM[2]);
    printf("3:[%02X]\n",RAM[3]);
    printf("4:[%02X]\n",RAM[4]);

}  //main




"01-02-0A"

[0][1](-)
g = #01. (1)
<->[0][2](-)
g = #02. (2)
<->[0][A](\0)
g = #0A. (10)

num:3
0:[01]
1:[02]
2:[0A]
3:[03]
4:[04]

おまけ(修正前)

  • オンライコンパイラ



//0 1 2 3 4 5 6 7 8 9 A B C D E F
char t[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //00
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //10
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //20
0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, //30

0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, //40
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //50
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //60
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //70

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //80
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //90
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //A0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //B0

0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //C0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //D0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //E0
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0  //F0
};

#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    unsigned char p[]="01-02-0A";
    
    
    int i = 0; //カウンター
    int a; //一時領域
    int g; //一時領域
    
    printf("\"%s\"\n\n",p);
    
    a = 0xff; 
    while(a != 0){
    
        //読み飛ばし
        //構造化プログラミング先読み
        a = p[i]; //読み出し
    
        while((t[a] == 0) && (a != '0') && (a != 0)){
        
            printf("<%c>",a); //debug
            
            i++; 
            a = p[i]; //読み出し
       
        }  //while
    
    
        //16進の間
        //構造化プログラミング先読み
        a = p[i]; //読み出し
    
        g = 0;
        while( ((t[a] != 0) || (a == '0')) && (a != 0)){
        
            printf("[%c]",a); //debug
            
            g = (g << 4) + t[a];
       
            i++;
            a = p[i]; //読み出し
       
        }  //while
    
        if( p[i] == 0 ) {
            printf("(\\0)"); //debug
        } else {
            printf("(%c)",p[i]); //debug
        }
    
        printf("\n");
        
        printf("g = #%02X. (%d)\n",g,g);
    
    }  //while 0
    
}  //main




"01-02-0A"

[0][1](-)
g = #01. (1)
<->[0][2](-)
g = #02. (2)
<->[0][A](\0)
g = #0A. (10)


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?