SlideShare uma empresa Scribd logo
1 de 3
Baixar para ler offline
Task: Perform addition, subtraction, division, and multiplication, of rational numbers on MIPS Mars
Programming Simulator by writing a code and print the answers (using macros) from the pictures
provided. Also, when you write the code make sure you follow this format,
format:
.macro print_int (%x)
li $v0, 1
add $a0, $zero, %x
syscall
.end_macro
print_int ($s0)
print_int (10)
Intro Settings Syscalls IDE Debugging Command Tools History Limitations Exception Handlers
Macros Acknowledgements MARS home Writing and Using Macros .macro, .end_macro,.eqv and
.include directives are new in MARS 4.3 Introduction to macros Patterson and Hennessy define a
macro as a pattern-matching and replacement facility that provides a simple mechanism to name
a frequently used sequence of instructions [1]. This permits the programmer to specify the
instruction sequence by invoking the macro. This requires only one line of code for each use
instead of repeatedly typing in the instruction sequence each time. It follows the axiom "define
once, use many times," which not only reduces the chance for error but also facilitates program
maintenance. Macros are like procedures (subroutines) in this sense but operate differently than
procedures. Procedures in MIPS assembly language follow particular protocols for procedure
definition, call and return. Macros operate by substituting the macro body for each use at the time
of assembly. This substitution is called macro expansion.. They do not require the protocols and
execution overhead of procedures. As a simple example, you may want to terminate your program
from a number of locations. If you are running from the MARS IDE, you will use system call 10,
exit. The instruction sequence is pretty easy 1i$v0,10syscal1 but still tedious. You can define a
macro, let's call it done, to represent this sequence [ begin{array}{l} text { macro done } text { i1 } $
text { vo, } 10 text { syscali } text { +end_macro } end{array} ] then invoke it whenever you wish
with the statement done At assembly time, the assembler will replace each occurrence of the
statement done with the two-statement sequence 1i$v0,10syscali This is the macro expansion.
The runtime simulator is unaware of macros or macro expansion. If running MARS from the
command line, perhaps you want to return a termination value. This can be done with syscall 17,
exit2, which takes the termination value as an argument. An equivalent macro, let's call it
terminate would be macro terminate (stermination_value) ii $a0, itermination_value li $v0,17
syscali .end_macro This macro defines a formal parameter to represent the termination value. You
would invoke it with the statement terminate (1) to terminate with value 1. Upon assembly, the
statement terminate (1) would be replaced byterninate (1) to terminate with value 1. Upon
assembly, the statement terainate (1) would be replaced by the three-statement sequence The
argument value, 1, is substituted wherever the formal parameter teermination_value appears in
the macro body. This is a textual substitution. Note that in this example the argument value must
be an integer, not a register name or a label, because the parameter is used as the second
operand in the Load Immediate operation. In MARS, a macro is similar to an extended (pseudo)
instruction. They are distinguished in that the expansion of extended instructions is supported by
an internally-defined specification language and mechanism which can manipulate argument
values. The macro facility can only substitute argument values as given, and it uses a separate
mechanism from extended instructions. Additional examples and details follow. How to define
macros The first line begins with a s macro directive followed by an optional list of formal
parameters. Placing commas between parameters and parentheses around the list is optional.
Each formal parameter is an identifier that begins with a s character. For cempatibility with the
SPIM preprocessor APP, it may alternatively begin with 5 , The lines that follow define the body of
the macro. Use the formal parameters as appropriate. The body may contain data segments as
well as text segments. The macro definition finishes with a .end_macro directive. See the Notes
below for additional information. How to use macros To invoke a macro, form a statement
consisting of the macro name and then one token for each. argument to be substituted for its
corresponding formal parameter by the assembler. The argument list may optionally be
surrounded by parentheses. Arguments may be separated either by spaces or commas. Macro
expansion is a pre-processing task for assemblers. Notes - A macro definition must appear before
its use. No forward references. - All macro definitions are local in cach file and they caninot be
global. - Nested macro definitions are not supported. No - macro directive should appear inside
body of a macro definition. - A macro definition can contain a call to a previously-defined macro.
Only backward references are allowed. - Labels placed in the body of a macro definition will not
have same name after macro expansion. During expansion, their name will be followed by Min
where I will be a unique number for each macro expansion. - Two macros with the same name but
different number of parameters are considered different and both can be used. - A macro defined
with the same name and same number of parameters as another macro defined before it will be
ignored. - Each argument in a macro call can only be a single language element (token). For
instance "4(St0)" cannot be an argument. - Macros are a part of the assembler, not the ISA. So
the syntax might be different with other assemblers. For compatibility with the SPIM simalator,
SPRM-shyle macras are a bro supported in MARS. SPIM-style macros are same as MARS but
formal parameters beginsupported in MARS. SPIM-style macros are same as MARS but formal
parameters begin with " " " instead of %" ". Examples - Printing an integer (argument may be
either an immediate value or register name): macro print_int (bx) if $vo, 1 add $a0,$2er0,8x
syscall iend_macro print_int ($80) print_int (10) - Printing a string (macro will first assign a label to
its parameter in data segment then print it): - Implementing a simple for-loop: The for macro has 4
parameters. kregiterator sbould be the name of a register which iterates from 8 tron to sto and in
each iferation tbedyMacrokame will be expanded and tun. Arguments for s from and ato can be
either a register name or an immediate value, and Mbodywaerokame should be name of a macro
that has no parameters. Macro source line numbers For purpose of error messaging and Text
Segment display, MARS attempts to display line numbers for both the definition and use of the
pertinent macro statement. If an error message shows the line number in the form "X->Y" (c.g.
"20->4"), then X is the line number in the expansion (use) where the error was detected and r is
the line number in the macro definition. In the Text Segment display of souree code, the macto
definition line number will be displayed within brackets, e.g. " <4> ", at the point of expansion. Line
numbers shoald correspond to the numbers you would see in the text editot. The .eqv directive
The -eqv directive (short for "equivalence") is also new in MARS 4,3. It is similar to #det ine in C or
C++, It is used to substitute an arbitrary string for an identifier. It is useful but much less powerful
than macros. It was developed independently of the macro facility. Using - eqv, you can specify
simple substitutions that provide "define once, use many times" capability at assembly pre-
processing time. For example, once you define( begin{array}{ll}text {. eqv LIMIT CTR } & $ t 2 text
{. eqv CLv CLEAR_CTR add CTR, $zero, } 0 text {. eqv }end{array} ) then you can refer to them in
subsequent code: li $V0,1 CLEAR CTR loop: move $a0, CrR syseall add CTR, CTR, 1 blt CTR,
LIMIT, loop CLERR_CTR During assembly pre-processing, the .eqv substitutions will be applied.
The resulting code is li $v0,1 add $t2,$zero,0 move $a0,$t2 syscall add $t2,$t2,1 blt $t2,20,100p
add $t2,$zero,0 which when run will display the values 0 through 19 on one line with no
intervening spaces. Note that the substitution string is not limited to a single token. Like , macro, .
eqv is local to the file in which it is defined, and must be defined prior to use. Macro bodies can
contain references to e equ directives. The ainclude directive The . inelude directive is also new in
MARS 4.3. It has one operand, a quoted filename, When the directive is carried out, the contents
of the specified file are substituted for the directive. This occurs during assembly preprocessing. It
is like #include in C or C+. . include is designed to make macro and equivalence (eqv directive)
use more convenient. Both macro definitions and equivalence definitions are local, which means
they can be used only in the same file where defined. Without . include, you would have to repeat
their definitions in every file where you want to use them. Besides being tedious, this is poor
programming practice; remenber "define once, use many times." Now you can define macros and
equivalences in a seperate file, then include it in any file where you want to use them. The .
inelude preprocessor will detect and flag any circular includes (file that includes itself, directly or
indirectly). The use of . include presents some challenges for error messaging and for source code
numbering in the Text Segment display. If a file being included has any assembly errors, the
filename and line number in the error message should refer to the file being included, not the file it
was substituted into. Similarly, the line number given in the Text Segment source code display
refers to the line in the file being included. Thus the displayed line numbers do not monotonically
increase - this is also the case when using the "assemble all" setting. Line numbers sbould
correspond to the numbers you would see in the text editor. As a simple example, you could
define the done macro (and others) in a separate file then include it wherever you need it.
Suppose "macros. asm contains the following: You could then include it in a different source file
something like this:During assembly preprocessing, this would be expanded to The assembler will
then perform the appropriate macro expansion. Acknowledgements The MARS macro facility was
developed in 2012 by Mohammad Hossein Sekhavat, sekhavat17@gmail.com, while an
engineering student at Sharif University in Tehran. MARS creators Pete and Ken are incredibly
grateful for his contribution! Pete developed . eqv and . include at about the same time.
References [1] Computer Organization and Design: The Hardware/Software Interface, Fourth
Edition, Patterson and Hennessy, Morgan Kauffman Publishers, 2009.

Mais conteúdo relacionado

Semelhante a Task Perform addition subtraction division and multiplic.pdf

C basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaManoj Kumar kothagulla
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosNick Weisenberger
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macrosAnand Kumar
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1venkatam
 
Safe Clearing of Private Data
Safe Clearing of Private DataSafe Clearing of Private Data
Safe Clearing of Private DataPVS-Studio
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobolSrinimf-Slides
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene BurmakoVasil Remeniuk
 
Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»e-Legion
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguageTanmay Modi
 
33443223 system-software-unit-iv
33443223 system-software-unit-iv33443223 system-software-unit-iv
33443223 system-software-unit-ivShaniya Fathimuthu
 

Semelhante a Task Perform addition subtraction division and multiplic.pdf (20)

Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
Maxbox starter
Maxbox starterMaxbox starter
Maxbox starter
 
Handout#04
Handout#04Handout#04
Handout#04
 
C basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kellaC basic questions&amp;ansrs by shiva kumar kella
C basic questions&amp;ansrs by shiva kumar kella
 
Getting started with Microsoft Excel Macros
Getting started with Microsoft Excel MacrosGetting started with Microsoft Excel Macros
Getting started with Microsoft Excel Macros
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
Safe Clearing of Private Data
Safe Clearing of Private DataSafe Clearing of Private Data
Safe Clearing of Private Data
 
Data structures
Data structuresData structures
Data structures
 
Ss4
Ss4Ss4
Ss4
 
Handout#05
Handout#05Handout#05
Handout#05
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene Burmako
 
Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
Lecture 3.mte 407
Lecture 3.mte 407Lecture 3.mte 407
Lecture 3.mte 407
 
33443223 system-software-unit-iv
33443223 system-software-unit-iv33443223 system-software-unit-iv
33443223 system-software-unit-iv
 

Mais de acsmadurai

T X Projection of Di An Fo Isobaric diagr illustrating.pdf
T  X Projection of Di  An  Fo Isobaric diagr illustrating.pdfT  X Projection of Di  An  Fo Isobaric diagr illustrating.pdf
T X Projection of Di An Fo Isobaric diagr illustrating.pdfacsmadurai
 
T Miyake y M Demerec examinaron mutaciones que requieren p.pdf
T Miyake y M Demerec examinaron mutaciones que requieren p.pdfT Miyake y M Demerec examinaron mutaciones que requieren p.pdf
T Miyake y M Demerec examinaron mutaciones que requieren p.pdfacsmadurai
 
Systen outprintln encrypted zessage Systezoutprin.pdf
Systen outprintln encrypted zessage   Systezoutprin.pdfSysten outprintln encrypted zessage   Systezoutprin.pdf
Systen outprintln encrypted zessage Systezoutprin.pdfacsmadurai
 
Suzy is a fourteen year old teenager she resides with her u.pdf
Suzy is a fourteen year old teenager she resides with her u.pdfSuzy is a fourteen year old teenager she resides with her u.pdf
Suzy is a fourteen year old teenager she resides with her u.pdfacsmadurai
 
Szl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdf
Szl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdfSzl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdf
Szl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdfacsmadurai
 
Symbiodinium is a dinoflagellate with a genome size that enc.pdf
Symbiodinium is a dinoflagellate with a genome size that enc.pdfSymbiodinium is a dinoflagellate with a genome size that enc.pdf
Symbiodinium is a dinoflagellate with a genome size that enc.pdfacsmadurai
 
Szleme hukuku S9 Kitty tm mal varln byk kz Meghana .pdf
Szleme hukuku  S9 Kitty tm mal varln byk kz Meghana .pdfSzleme hukuku  S9 Kitty tm mal varln byk kz Meghana .pdf
Szleme hukuku S9 Kitty tm mal varln byk kz Meghana .pdfacsmadurai
 
Tace rie to the tent Gedit coling Assume the foltowng hist.pdf
Tace rie to the tent Gedit coling Assume the foltowng hist.pdfTace rie to the tent Gedit coling Assume the foltowng hist.pdf
Tace rie to the tent Gedit coling Assume the foltowng hist.pdfacsmadurai
 
symbol inputEnter stock ticker a symbolsplit .pdf
symbol  inputEnter stock ticker  a symbolsplit  .pdfsymbol  inputEnter stock ticker  a symbolsplit  .pdf
symbol inputEnter stock ticker a symbolsplit .pdfacsmadurai
 
Symons Vs Heaton Gary Plachek and Curtis Symons met in 1.pdf
Symons Vs Heaton    Gary Plachek and Curtis Symons met in 1.pdfSymons Vs Heaton    Gary Plachek and Curtis Symons met in 1.pdf
Symons Vs Heaton Gary Plachek and Curtis Symons met in 1.pdfacsmadurai
 
tances along a road in a forest The skidding distances in .pdf
tances along a road in a forest The skidding distances in .pdftances along a road in a forest The skidding distances in .pdf
tances along a road in a forest The skidding distances in .pdfacsmadurai
 
taught enough math and science Do parents feel differently .pdf
taught enough math and science Do parents feel differently .pdftaught enough math and science Do parents feel differently .pdf
taught enough math and science Do parents feel differently .pdfacsmadurai
 
Synergy effects is abstractly defined as the interplay betw.pdf
Synergy effects is abstractly defined as  the interplay betw.pdfSynergy effects is abstractly defined as  the interplay betw.pdf
Synergy effects is abstractly defined as the interplay betw.pdfacsmadurai
 
Telehealthtelemedicine has become increasingly important i.pdf
Telehealthtelemedicine has become increasingly important i.pdfTelehealthtelemedicine has become increasingly important i.pdf
Telehealthtelemedicine has become increasingly important i.pdfacsmadurai
 
Tablo 102 Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdf
Tablo 102  Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdfTablo 102  Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdf
Tablo 102 Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdfacsmadurai
 
Team ProjectPresentation 20 Students are expected to wo.pdf
Team ProjectPresentation 20  Students are expected to wo.pdfTeam ProjectPresentation 20  Students are expected to wo.pdf
Team ProjectPresentation 20 Students are expected to wo.pdfacsmadurai
 
Tek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdf
Tek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdfTek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdf
Tek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdfacsmadurai
 
Tedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdf
Tedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdfTedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdf
Tedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdfacsmadurai
 
TCL global strategy at one of Chinas largest consumer e.pdf
TCL   global strategy at one of Chinas largest consumer e.pdfTCL   global strategy at one of Chinas largest consumer e.pdf
TCL global strategy at one of Chinas largest consumer e.pdfacsmadurai
 
TCO 1 Celeste pasa la mayor parte de su tiempo en el tra.pdf
TCO 1  Celeste pasa la mayor parte de su tiempo en el tra.pdfTCO 1  Celeste pasa la mayor parte de su tiempo en el tra.pdf
TCO 1 Celeste pasa la mayor parte de su tiempo en el tra.pdfacsmadurai
 

Mais de acsmadurai (20)

T X Projection of Di An Fo Isobaric diagr illustrating.pdf
T  X Projection of Di  An  Fo Isobaric diagr illustrating.pdfT  X Projection of Di  An  Fo Isobaric diagr illustrating.pdf
T X Projection of Di An Fo Isobaric diagr illustrating.pdf
 
T Miyake y M Demerec examinaron mutaciones que requieren p.pdf
T Miyake y M Demerec examinaron mutaciones que requieren p.pdfT Miyake y M Demerec examinaron mutaciones que requieren p.pdf
T Miyake y M Demerec examinaron mutaciones que requieren p.pdf
 
Systen outprintln encrypted zessage Systezoutprin.pdf
Systen outprintln encrypted zessage   Systezoutprin.pdfSysten outprintln encrypted zessage   Systezoutprin.pdf
Systen outprintln encrypted zessage Systezoutprin.pdf
 
Suzy is a fourteen year old teenager she resides with her u.pdf
Suzy is a fourteen year old teenager she resides with her u.pdfSuzy is a fourteen year old teenager she resides with her u.pdf
Suzy is a fourteen year old teenager she resides with her u.pdf
 
Szl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdf
Szl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdfSzl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdf
Szl ve poster sunumlar arasndaki benzerlik ve farkllklar a.pdf
 
Symbiodinium is a dinoflagellate with a genome size that enc.pdf
Symbiodinium is a dinoflagellate with a genome size that enc.pdfSymbiodinium is a dinoflagellate with a genome size that enc.pdf
Symbiodinium is a dinoflagellate with a genome size that enc.pdf
 
Szleme hukuku S9 Kitty tm mal varln byk kz Meghana .pdf
Szleme hukuku  S9 Kitty tm mal varln byk kz Meghana .pdfSzleme hukuku  S9 Kitty tm mal varln byk kz Meghana .pdf
Szleme hukuku S9 Kitty tm mal varln byk kz Meghana .pdf
 
Tace rie to the tent Gedit coling Assume the foltowng hist.pdf
Tace rie to the tent Gedit coling Assume the foltowng hist.pdfTace rie to the tent Gedit coling Assume the foltowng hist.pdf
Tace rie to the tent Gedit coling Assume the foltowng hist.pdf
 
symbol inputEnter stock ticker a symbolsplit .pdf
symbol  inputEnter stock ticker  a symbolsplit  .pdfsymbol  inputEnter stock ticker  a symbolsplit  .pdf
symbol inputEnter stock ticker a symbolsplit .pdf
 
Symons Vs Heaton Gary Plachek and Curtis Symons met in 1.pdf
Symons Vs Heaton    Gary Plachek and Curtis Symons met in 1.pdfSymons Vs Heaton    Gary Plachek and Curtis Symons met in 1.pdf
Symons Vs Heaton Gary Plachek and Curtis Symons met in 1.pdf
 
tances along a road in a forest The skidding distances in .pdf
tances along a road in a forest The skidding distances in .pdftances along a road in a forest The skidding distances in .pdf
tances along a road in a forest The skidding distances in .pdf
 
taught enough math and science Do parents feel differently .pdf
taught enough math and science Do parents feel differently .pdftaught enough math and science Do parents feel differently .pdf
taught enough math and science Do parents feel differently .pdf
 
Synergy effects is abstractly defined as the interplay betw.pdf
Synergy effects is abstractly defined as  the interplay betw.pdfSynergy effects is abstractly defined as  the interplay betw.pdf
Synergy effects is abstractly defined as the interplay betw.pdf
 
Telehealthtelemedicine has become increasingly important i.pdf
Telehealthtelemedicine has become increasingly important i.pdfTelehealthtelemedicine has become increasingly important i.pdf
Telehealthtelemedicine has become increasingly important i.pdf
 
Tablo 102 Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdf
Tablo 102  Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdfTablo 102  Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdf
Tablo 102 Bir i merkezinde ilenmeyi bekleyen aadaki alt i .pdf
 
Team ProjectPresentation 20 Students are expected to wo.pdf
Team ProjectPresentation 20  Students are expected to wo.pdfTeam ProjectPresentation 20  Students are expected to wo.pdf
Team ProjectPresentation 20 Students are expected to wo.pdf
 
Tek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdf
Tek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdfTek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdf
Tek yumurta ikizleri ayn yumurtadan gelir ve dolaysyla ayn c.pdf
 
Tedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdf
Tedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdfTedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdf
Tedarik iin ortak hedefler aadakilerin tmn ierir HAR.pdf
 
TCL global strategy at one of Chinas largest consumer e.pdf
TCL   global strategy at one of Chinas largest consumer e.pdfTCL   global strategy at one of Chinas largest consumer e.pdf
TCL global strategy at one of Chinas largest consumer e.pdf
 
TCO 1 Celeste pasa la mayor parte de su tiempo en el tra.pdf
TCO 1  Celeste pasa la mayor parte de su tiempo en el tra.pdfTCO 1  Celeste pasa la mayor parte de su tiempo en el tra.pdf
TCO 1 Celeste pasa la mayor parte de su tiempo en el tra.pdf
 

Último

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 

Último (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 

Task Perform addition subtraction division and multiplic.pdf

  • 1. Task: Perform addition, subtraction, division, and multiplication, of rational numbers on MIPS Mars Programming Simulator by writing a code and print the answers (using macros) from the pictures provided. Also, when you write the code make sure you follow this format, format: .macro print_int (%x) li $v0, 1 add $a0, $zero, %x syscall .end_macro print_int ($s0) print_int (10) Intro Settings Syscalls IDE Debugging Command Tools History Limitations Exception Handlers Macros Acknowledgements MARS home Writing and Using Macros .macro, .end_macro,.eqv and .include directives are new in MARS 4.3 Introduction to macros Patterson and Hennessy define a macro as a pattern-matching and replacement facility that provides a simple mechanism to name a frequently used sequence of instructions [1]. This permits the programmer to specify the instruction sequence by invoking the macro. This requires only one line of code for each use instead of repeatedly typing in the instruction sequence each time. It follows the axiom "define once, use many times," which not only reduces the chance for error but also facilitates program maintenance. Macros are like procedures (subroutines) in this sense but operate differently than procedures. Procedures in MIPS assembly language follow particular protocols for procedure definition, call and return. Macros operate by substituting the macro body for each use at the time of assembly. This substitution is called macro expansion.. They do not require the protocols and execution overhead of procedures. As a simple example, you may want to terminate your program from a number of locations. If you are running from the MARS IDE, you will use system call 10, exit. The instruction sequence is pretty easy 1i$v0,10syscal1 but still tedious. You can define a macro, let's call it done, to represent this sequence [ begin{array}{l} text { macro done } text { i1 } $ text { vo, } 10 text { syscali } text { +end_macro } end{array} ] then invoke it whenever you wish with the statement done At assembly time, the assembler will replace each occurrence of the statement done with the two-statement sequence 1i$v0,10syscali This is the macro expansion. The runtime simulator is unaware of macros or macro expansion. If running MARS from the command line, perhaps you want to return a termination value. This can be done with syscall 17, exit2, which takes the termination value as an argument. An equivalent macro, let's call it terminate would be macro terminate (stermination_value) ii $a0, itermination_value li $v0,17 syscali .end_macro This macro defines a formal parameter to represent the termination value. You would invoke it with the statement terminate (1) to terminate with value 1. Upon assembly, the statement terminate (1) would be replaced byterninate (1) to terminate with value 1. Upon assembly, the statement terainate (1) would be replaced by the three-statement sequence The argument value, 1, is substituted wherever the formal parameter teermination_value appears in the macro body. This is a textual substitution. Note that in this example the argument value must be an integer, not a register name or a label, because the parameter is used as the second operand in the Load Immediate operation. In MARS, a macro is similar to an extended (pseudo)
  • 2. instruction. They are distinguished in that the expansion of extended instructions is supported by an internally-defined specification language and mechanism which can manipulate argument values. The macro facility can only substitute argument values as given, and it uses a separate mechanism from extended instructions. Additional examples and details follow. How to define macros The first line begins with a s macro directive followed by an optional list of formal parameters. Placing commas between parameters and parentheses around the list is optional. Each formal parameter is an identifier that begins with a s character. For cempatibility with the SPIM preprocessor APP, it may alternatively begin with 5 , The lines that follow define the body of the macro. Use the formal parameters as appropriate. The body may contain data segments as well as text segments. The macro definition finishes with a .end_macro directive. See the Notes below for additional information. How to use macros To invoke a macro, form a statement consisting of the macro name and then one token for each. argument to be substituted for its corresponding formal parameter by the assembler. The argument list may optionally be surrounded by parentheses. Arguments may be separated either by spaces or commas. Macro expansion is a pre-processing task for assemblers. Notes - A macro definition must appear before its use. No forward references. - All macro definitions are local in cach file and they caninot be global. - Nested macro definitions are not supported. No - macro directive should appear inside body of a macro definition. - A macro definition can contain a call to a previously-defined macro. Only backward references are allowed. - Labels placed in the body of a macro definition will not have same name after macro expansion. During expansion, their name will be followed by Min where I will be a unique number for each macro expansion. - Two macros with the same name but different number of parameters are considered different and both can be used. - A macro defined with the same name and same number of parameters as another macro defined before it will be ignored. - Each argument in a macro call can only be a single language element (token). For instance "4(St0)" cannot be an argument. - Macros are a part of the assembler, not the ISA. So the syntax might be different with other assemblers. For compatibility with the SPIM simalator, SPRM-shyle macras are a bro supported in MARS. SPIM-style macros are same as MARS but formal parameters beginsupported in MARS. SPIM-style macros are same as MARS but formal parameters begin with " " " instead of %" ". Examples - Printing an integer (argument may be either an immediate value or register name): macro print_int (bx) if $vo, 1 add $a0,$2er0,8x syscall iend_macro print_int ($80) print_int (10) - Printing a string (macro will first assign a label to its parameter in data segment then print it): - Implementing a simple for-loop: The for macro has 4 parameters. kregiterator sbould be the name of a register which iterates from 8 tron to sto and in each iferation tbedyMacrokame will be expanded and tun. Arguments for s from and ato can be either a register name or an immediate value, and Mbodywaerokame should be name of a macro that has no parameters. Macro source line numbers For purpose of error messaging and Text Segment display, MARS attempts to display line numbers for both the definition and use of the pertinent macro statement. If an error message shows the line number in the form "X->Y" (c.g. "20->4"), then X is the line number in the expansion (use) where the error was detected and r is the line number in the macro definition. In the Text Segment display of souree code, the macto definition line number will be displayed within brackets, e.g. " <4> ", at the point of expansion. Line numbers shoald correspond to the numbers you would see in the text editot. The .eqv directive
  • 3. The -eqv directive (short for "equivalence") is also new in MARS 4,3. It is similar to #det ine in C or C++, It is used to substitute an arbitrary string for an identifier. It is useful but much less powerful than macros. It was developed independently of the macro facility. Using - eqv, you can specify simple substitutions that provide "define once, use many times" capability at assembly pre- processing time. For example, once you define( begin{array}{ll}text {. eqv LIMIT CTR } & $ t 2 text {. eqv CLv CLEAR_CTR add CTR, $zero, } 0 text {. eqv }end{array} ) then you can refer to them in subsequent code: li $V0,1 CLEAR CTR loop: move $a0, CrR syseall add CTR, CTR, 1 blt CTR, LIMIT, loop CLERR_CTR During assembly pre-processing, the .eqv substitutions will be applied. The resulting code is li $v0,1 add $t2,$zero,0 move $a0,$t2 syscall add $t2,$t2,1 blt $t2,20,100p add $t2,$zero,0 which when run will display the values 0 through 19 on one line with no intervening spaces. Note that the substitution string is not limited to a single token. Like , macro, . eqv is local to the file in which it is defined, and must be defined prior to use. Macro bodies can contain references to e equ directives. The ainclude directive The . inelude directive is also new in MARS 4.3. It has one operand, a quoted filename, When the directive is carried out, the contents of the specified file are substituted for the directive. This occurs during assembly preprocessing. It is like #include in C or C+. . include is designed to make macro and equivalence (eqv directive) use more convenient. Both macro definitions and equivalence definitions are local, which means they can be used only in the same file where defined. Without . include, you would have to repeat their definitions in every file where you want to use them. Besides being tedious, this is poor programming practice; remenber "define once, use many times." Now you can define macros and equivalences in a seperate file, then include it in any file where you want to use them. The . inelude preprocessor will detect and flag any circular includes (file that includes itself, directly or indirectly). The use of . include presents some challenges for error messaging and for source code numbering in the Text Segment display. If a file being included has any assembly errors, the filename and line number in the error message should refer to the file being included, not the file it was substituted into. Similarly, the line number given in the Text Segment source code display refers to the line in the file being included. Thus the displayed line numbers do not monotonically increase - this is also the case when using the "assemble all" setting. Line numbers sbould correspond to the numbers you would see in the text editor. As a simple example, you could define the done macro (and others) in a separate file then include it wherever you need it. Suppose "macros. asm contains the following: You could then include it in a different source file something like this:During assembly preprocessing, this would be expanded to The assembler will then perform the appropriate macro expansion. Acknowledgements The MARS macro facility was developed in 2012 by Mohammad Hossein Sekhavat, sekhavat17@gmail.com, while an engineering student at Sharif University in Tehran. MARS creators Pete and Ken are incredibly grateful for his contribution! Pete developed . eqv and . include at about the same time. References [1] Computer Organization and Design: The Hardware/Software Interface, Fourth Edition, Patterson and Hennessy, Morgan Kauffman Publishers, 2009.