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?

More than 1 year has passed since last update.

8ビットの掛け算(小規模マイコン)(教育)

Last updated at Posted at 2023-11-28

8ビットの掛け算(小規模マイコン)(教育)

目的
ビットを見てシフトして加算器に足していくやつ
乗算器の内部では、こんな事が行われているかも?
教育目的

いろいろ
したい事は、画面のアドレス計算を高速にしたい。
320,256,240,192,160,128とか。
256は、左シフト8回
128は、左シフト7回
320は、左シフト3回と加算2回の答えを左シフト5回
160は、左シフト3回と加算2回の答えを左シフト4回
240は、左シフト4回と引き算1回の答えを左シフト4回
シフト2回+加算1回ぐらいだと、思わずシフトでやってしまう。
192は、今、流行りのMSXの縦の大きさ(128+64=192)


al = (al << 7) + (al << 6);

オンラインコンパイラ

axは、アキュムレータ(本来は、使いまくる 簡素している)
符号の処理は、ない
正の数の整数



#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    //int ax; //アキュムレータ
    int bx; //掛ける数
    int cx; //掛ける数
    int dx; //答え
    
    bx=64;
    cx=3;
    dx=0;
    
    
    if(bx & 0x80) {printf("[80H]");dx=dx+(cx<<7);}
    if(bx & 0x40) {printf("[40H]");dx=dx+(cx<<6);}
    if(bx & 0x20) {printf("[20H]");dx=dx+(cx<<5);}
    if(bx & 0x10) {printf("[10H]");dx=dx+(cx<<4);}
    
    if(bx & 0x08) {printf("[08H]");dx=dx+(cx<<3);}
    if(bx & 0x04) {printf("[04H]");dx=dx+(cx<<2);}
    if(bx & 0x02) {printf("[02H]");dx=dx+(cx<<1);}
    if(bx & 0x01) {printf("[01H]");dx=dx+(cx<<0);}

    printf("\n");
    
    //printf("ax=[%d]\n",ax);
    printf("bx=[%d]\n",bx);
    printf("cx=[%d]\n",cx);
    printf("dx=[%d]\n",dx);

}




結果


[40H]
bx=[64]
cx=[3]
dx=[192]


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?