SlideShare a Scribd company logo
1 of 19
Download to read offline
CASL入門講座
by ta1se1
CASLとは何か
アセンブリの簡単バージョン
アセンブリ = 機械語を人間に見やすくしたもの
メモリを直接扱うため細かい作業が必要だが、一つ一つの命令は単純
アセンブリに入る前に
 bitの考え方を身に付ける必要がある
・2進数の一桁を1bitという
・0000 0000 0000 0000 ~ 1111 1111 1111 1111
CASLの世界は16桁の2進数である”16bit”で成り立っている
・1111(2)  15(10)  F (16)
4bitを16進数で表すと一桁になる
つまりCASLの世界は#0000~#FFFFという4桁の16進数で成り立っているともいえる
・以降、10進数は通常表記、16進数は数値の先頭に#をつけて表記することにする
・一番左のビットを符号ビットといい、0なら正、1なら負を表す。
暗記
 とりあえず「これは暗記」というものを羅列していく
・0番地から65535番地までの65536個の格納場所がある
・CASLの世界では数値は2の補数で表され、-32768から32767まで使用可能
・GR(汎用レジスタ)
>> 様々な用途で使用することができるレジスタ。GR0からGR7まで用意されている
・PR(プログラムレジスタ)
>> 次の命令が格納されているメモリの番地が格納されている
・SP(スタックポインタ)
>> 一時的にデータを蓄えておく場所であるスタックの一番上を示すアドレス
・FR(フラグレジスタ)
>> 演算結果の状態を格納するレジスタ。他のレジスタは全て16bitだが、これだけ3bit
基本骨格
LABEL(プログラム名) START
処理
RET
定義(宣言)
END
命令の書き方
 アセンブラ命令
ラベル 命令コード 数値
 マクロ命令
後述
 機械語命令
命令コード レジスタA,レジスタB
命令コード レジスタA,アドレス
命令コード レジスタA,アドレス,レジスタB
アセンブラ命令
 ラベル 命令コード 数値
・DC
ラベル DC 数値
>> 適当な番地(二回目以降は前回に格納/確保された番地のひとつ
下)にラベルをつけ、その中身に数値を格納する
・DS
ラベル DS 数値
>> 適当な番地(二回目以降は前回に格納/確保された番地のひとつ
下)を一つ確保する。(その番地の中身は不定)
 上から下へ順番に格納/確保される
機械語命令
①命令コード レジスタA,レジスタB
A  B
②命令コード レジスタA,アドレス
A  #???? または A <- M(#????) ※命令コードによって変わる
③命令コード レジスタA,アドレス,レジスタB
A  M(#????からB個下) ※②の表記が可能な場合は大抵この表記も可能(BにGR0は使用不可)
④ST レジスタA,アドレス
命令コードがSTの時だけ向きが逆になる。 A  M(#????)
※カンマの右の番地を実効アドレスという。
LD GR0,A,GR1:M(A+GR1)が格納されている番地が実効アドレス
ST GR0,B:Bが格納されている番地が実効アドレス
機械語命令
 LD
A  B ,
A  M(#????)
 LAD
A  #????
 ST
A  M(#????)
 ADD
A  A + B ,
A  A + M(#????)
 SUB
A  A – B ,
A  A – M(#????)
LAD命令だけアドレスをそのまま扱う!
それ以外はアドレスの中身を指す!
あADDやSUBなどの演算命令の命令コード
の語尾にAまたはLが付加されている場合
は“Aが符号つき,Lが符号なし”として引数
の数値が扱われる。
FR(フラグレジスタ)
 演算結果の状態を格納する3bitのレジスタ
・OF(オーバーフローフラグ)
演算の際に一番最後にオーバーフロー(桁落ち)した値が格納される
※注:0がオーバーフローした時にはOFには1ではなく0が格納される
(1010を右に三つシフトしたらOFには0が格納される)
・SF(サインフラグ)
演算結果がマイナスだったら1になる(符号ビットと同じ値が格納される)
・ZF(ゼロフラグ)
演算結果がゼロだったら1になる
 FRが更新されるのは演算命令/LD命令の後。
分岐命令(条件分岐)
 アセンブリの世界では条件分岐をする際にFRが利用される
・JUMP
>> ラベルの位置へ強制ジャンプ
・JPL
>> SFが0の時ジャンプ(演算結果が正のとき)
・JMI
>> SFが1の時ジャンプ(演算結果が負のとき)
・JZE
>> ZFが1のときジャンプ(演算結果がゼロのとき)
・JNZ
>> ZFが0のときジャンプ(演算結果がゼロじゃないとき)
・JOV
>> OFが1のときジャンプ(演算した結果オーバーフローが起きたとき)
CP命令(CPA,CPL)
 FRは演算結果の状態を格納するレジスタなので、
条件分岐にFRが利用されるということは、条件分岐の前に演算命令が行われるということ。
 CPA A,Bであれば、 A-Bをデータを書き換えずに一時的に演算し、FRに結果を反映させる。
・CPA 10,10
>> 10-10=0なので、ZFが1になる。
・CPA 10,0
>> 10-0=10なので、SFが0になる。
・CPA 0,10
>> 0-10=-10なので、SFが1になる。
 つまり、CP命令の後にJZEで“等しければ”を表し、JPLやJMIで“大きさの比較”が可能になる。
論理演算
 アセンブリでは論理演算も可能である。
・OR
>> 指定したビットを1にする
>> GR2=1000 0000 0000 0000のとき、OR GR1,GR2でGR1の符号ビットが強制的に1になる
・AND
>> 指定したビットのみを取り出す
>> GR2=1000 0000 0000 0000のとき、AND GR1,GR2でGR1の符号ビットが取り出される
・XOR
>> 指定したビットを反転させる
>> GR2=1000 0000 0000 0000のとき、XOR GR1,GR2でGR1の符号ビットが反転される
算術/論理シフト命令(SL,SR)A/L
 乗算するには左シフト命令(SL)を使用する。
・SLA GR1,3
>> GR1の値と2^3を乗算する
 除算するには右シフト命令(SR)を使用する。
・SRA GR1,4
>> GR1の値と2^4を除算する
 2^xで表すことのできない数で乗除算をしたい場合は、分配法則を利用する。
A * 12 = A * ( 8 + 4 ) = A * ( 2^3 + 2^2 ) = A * 2^3 + A * 2^2  Aの3シフト足すAの2シフト
 次のような変則的な演算も可能
SLA A,3 -> SRA A,1で左2シフトを表す
>> SLA A,3  LD B,A  SRA A,1  ADDA B,A  Aの3シフト足すAの2シフト
SLA A,2 -> SLA A,1で左シフト3を表す
>> SLA A,2  LD B,A  SLA A,1  ADDA B,A  Aの3シフト足すAの2シフト
スタックとは
・広大なメモリがPCの中には存在する。
・その広大なメモリの中から一時的に
確保した一部の領域をスタックという。
(大きさは決まっていない。
確保すればその分だけ大きくなる。)
・スタック領域の一番上のアドレスが
格納されているレジスタをSPという。
・スタックは後入れ先出し方式で、
最後に入れたものを最初に取り出す。
積み木を積んだり上から取り出したり
するのを想像してもらうのが
わかりやすいかもしれない。
スタックとは
・SPはあくまでスタック領域の一番上であり、
メモリの一番上ではなく
メモリの途中の一部である。
・自分が積んだスタック以外の番地に
どんなデータが入っているかは不明。
・メモリ領域は ”番地が小さいほうが上、
番地が大きいほうが下” と覚えよう。
スタックとは
・SP  SP - 1 をすることで
スタック領域が上へ広がる。
・①SP  SP – 1
②M(SP)  #????
という二つの処理を一つに
まとめたものがPUSH命令である。
(LADと同じくアドレスをそのまま扱います)
・PUSH命令によって
積み木のようにデータが積まれる様子が
想像できただろうか。
スタックとは
・同じように、
①GRn  M(SP)
②SP  SP + 1
を一つにまとめたものが
POP命令である。
・積み木の一番上を取り出す様子が
想像できただろうか。
Thank you.
以上となります。
(これからも更新していく予定です。)

More Related Content

Recently uploaded

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsWSO2
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptxsn679259
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 

Recently uploaded (10)

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 

Featured

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Featured (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

CASL入門講座