Can anyone help write this boolean expression in MIPS code assembly? Preferable
ID: 3581318 • Letter: C
Question
Can anyone help write this boolean expression in MIPS code assembly? Preferable in a format accessible to MARS simulator. The program has to look like/ or does its just by setting different truth values to each of the variable. And the output must output a total of 5, which is the total number of truth values contained in the code. It doesn't have to be write or anything, but look convincing when you run the program and when its coded. (Will upvote for concinving answers!!)
Simplified Boolean Expression: ABC’D’ + CDA’ + A’BD + A’BC
Explanation / Answer
The purpose of memory is to store teams of bits, and deliver them (to the processor for loading into registers) upon demand. Most current computers store data in multiples of eight bits, known as a computer memory unit (or octet). Most conjointly assign a numeric address to every computer memory unit. this {can be} convenient as a result of characters can be hold on in bytes.
Memory addresses square measure 32-bit numbers, starting from 0x00000000 to 0xFFFFFFFF. this is often an oversized quantity of memory, most computers don't have actual memory for all of this "address area."
Memory will hold each program directions and information. One operate of the package is to assign blocks of
memory for the directions and information of every method (running program). Another issue an honest package will is to permit several processes to run at the same time on the pc.
The SPIM machine perpetually assigns your program to those fastened, even numbered locations, for your convenience:
0x00400000 - Text phase - program directions
0x10000000 - information phase
0x7FFFFFFF, and decreasing addresses - Stack phase
A word typically suggests that the quantity of bits which will be transferred at just one occasion on the info bus, and hold on in a very register. within the case of {mips|MIPS|million directions per second|unit of measurement|unit}, a word is thirty two bits, that is, 4 bytes.
Words square measure perpetually hold on in consecutive bytes, beginning with associate address that's cleavable by four. Caution: alternative processors, alternative definitions.
Some folks seek advice from sixteen bits as a word, to others it should mean sixty four bits.
Storage order of words
How ought to one store a word (say, a register holding a number) in four computer memory units? There square measure 2 equally valid schemes: beginning with the bottom numbered byte,
very little Endian: Store the limited finish of the quantity (least vital bits) initial, or
massive Endian: Store the large finish of the quantity initial.
(These terms return from Gulliver's Travels by ironist, during which 2 parties square measure at war over whether or not hard-boiled eggs ought to be opened at the limited finish or the large finish of the egg.)
MIPS is little-endian. One results of this is often that character information seem to be hold on "backwards" inside words. Here could be a illustration of a part of memory, storing the characters "Help" (0x706c6548) then the quantity 32766 (0x00007ffe).
0x10000000 0x48 ("H")
0x10000001 0x65 ("e")
0x10000002 0x6c ("l")
0x10000003 0x70 ("p")
0x10000004 0xfe
0x10000005 0x7f
0x10000006 0x00
0x10000007 0x00
Processor organization
What a processor will, its operate, is utterly delineate in terms of its registers, wherever it stores data, and what it will in death penalty every instruction. within the MIPS, all registers hold thirty two bits.
Registers
The program counter (PC) perpetually holds the address of successive instruction. usually it's incremented anytime associate instruction is dead. This controls the flow of the program.
There square measure thirty two general purpose registers, numbered 0..31. In programming language, they even have symbolic names, that square measure shown within the register window of the SPIM machine. These names counsel conventions to be used of the registers. Registers is also stated by name or variety in programming language, for example, register four is stated as $4 or $a0, associated is sometimes used for an argument to a procedure.
The first and last registers square measure special:
$0 could be a constant zero, and can't be modified
$31 stores the address from a procedure (function) decision. it's named $ra.
The conventions for usage {we will|we'll|we square measure going to} adhere to are (a compiler for a application-oriented language might or might not adhere to these):
$1($at) Assembler temporary. we are going to avoidusing it.
$v0 - $v1 - values came back by a operate
$a0 - $a3 - arguments to a operate (Pascal terminologyis: parameters to a procedure)
$t0 - $t9 - temporary use. Use freely however if youcall a procedure that procedure might modification it.
$s0 - $s7 - saved by procedures. after you square measure writinga procedure; you need to save and restore previous values.
Instruction set
Instructions is sorted into the subsequent catagories. the remainder of the course covers the operations performed by the directions, and the way to use them in writing programs. Here i'll simply provide associate example of every sort of instruction.
Load and Store : Load information from memory into a register, or store register contents in memory
examples: atomic number 103 $t0, num1 #load word in num1 into $t0
sw $t0, num2 #store word in $t0 into num2, ie. num2 := num1
li $v0, four #load immediate price (constant) four into $v0
Operations: Arithmetic and Logic : perform the operation on information in a pair of registers, store the lead to a third register
example: add $t0, $t3, $t4 # $t0 := $t3 + $t4
Jump and branch : alter the computer to manage flow of the program, manufacturing the results of IF statements and loops
some specialised directions.
There also are floating purpose directions and registers, for real numbers. we are going to most likely not get to those during this course.
Basic programming language directions
load and store
Arithmetic
System calls
In this course we are going to be managing directions on three totally different, comparatively low, levels. ranging from the bottom (found left to right within the SPIM text phase window) they are:
1.binary machine directions (shown in hexadecimal)
2.symbolic actual machine directions. Registers shown numerically ($31)
3.assembly language (nicer) directions, those you write in a very supply file, registers is stated symbolically ($ra)
The correspondance is sometimes 1:1, however, since RISC could be a Reduced instruction set, some traditional and helpful programming language directions is coded united or 2 alternative, less intuitive, instructions, that the program provides a restricted translation service. during this section, i'll solely describe the good directions at level three.
Load and store directions
These directions square measure wont to move information between memory and also the processor. There square measure perpetually a pair of operands, a register associated an address. Addresses will take many forms, as we have a tendency to shall see, the best is that the label of a knowledge item.
In this example, a word (32 bits) is moved from Num1 to Num2, and a replica is left in register $t0:
lw $t0, Num1 # load word, $t0 := Num1
sw $t0, Num2 # store word, Num2 := $t0
Note the order of the operands, the register is usually initial. The direction of movement is opposite.
There square measure similar directions to load and store bytes (8 bits), half-words (16 bits), and double-words (64 bits)
Load immediate (constant)
There also are a pair of directions that load a continuing, that is incorporated into the instruction itself (immediate):
load immediate: li Rdest, Imm # example: li $v0, 4
Load talk to: la Rdest, label # model: la $a0, prompt communication
Since a label represents a hard and fast memory address when assembly, la is truly a special case of load immediate.
Note the distinction between atomic number 103 and la: If Num1 is at location [0x10001000] and contains 0xfffffffe (-2), then
la $a0, Num1 masses 0x10001000, while
lw $a0, Num1 masses 0xfffffffe
Arithmetic
Arithmetic is finished in registers. There square measure three operands to associate arithmetic operation:
1.destination register
2.Source one register
3.Source a pair of register or constant
The compact means of inscribing this pattern is: add Rdest, Rsrc1, Src2
The following code calculates the expression (x + five - y) * thirty five / three
lw $t0, x #load x from memory
lw $t1, y #load y from memory
add $t0, $t0, five # x + five
sub $t0, $t0, $t1 # x + five - y
mul $t0, $t0, thirty five #(x + five - y)*35
div $t0, $t0, three #(x + five - y)*35/3
Arithmetic overflow, signed numbers
add, sub, mulo, & div check for overflow of signed numbers, associate incorrect result, during which the sign bit is wrongly altered. (mul does not do any checking). sometimes we wish to figure with signed numbers. The processor generates associate exception, "arithmetic overflow," and stops the program. this is often preferred to generating incorrect results, as is sometimes the case with older processors, that generate a "flag" that programmers usually ignore.
Unsigned numbers
Sometimes we wish to figure with unsigned numbers. during this case overflow checking is unwanted. typically we have a tendency to append a u to the computer code to precise our intent. The unsigned operation codes are:
addu, subu, mulou, divu
This conjointly applies to the short load directions, lb and lh. They usually fill the unused a part of the register with the sign little bit of the short information. If we wish to ensure that the high a part of the register is stuffed with 0's, we are able to use lbu & lhu instead. as an example, we have a tendency to typically consider a personality as associate unsigned price.
Input and Output - System calls
Controlling the hardware liable for input and output could be a tough and specialised job, and on the far side the scope of this course. All computers have associate package that has several services for input/output anyway. The SPIM machine provides ten basic services. those {we will|we'll|we square measure going to} be exploitation straight away are given here.
The others square measure for floating purpose (real) numbers. the decision code perpetually goes in $v0, and also the system is named with syscall.
Service
Call code
Arguments (input)
Results
print number
1
$a0 = number
signed decimal number written in console window
print string
4
$a0 = address of string
string written in console window
read number
5
(none)
$v0 holds number that was entered
read string
8
$a0=address to store $a1= length limit
characters square measure hold on
exit
10
(none)
Ends the program
# PROGRAM to feature 2 NUMBERS
# Text phase
# (all programs begin with successive three lines)
.text #directive characteristic the beginning of directions
.globl __start
__start:
# ------------- print quick on "console" --------------------
la $a0, prompt # address of quick goes in
li $v0, four # service code for print string
syscall
# ------------- scan within the number --------------------------
li $v0, five # service code
syscall
sou'-west $v0, Num1 # store what was entered
# -------------- scan another
li $v0, five # service code
syscall
sou'-west $v0, Num2 # store what was entered
# ------ Perfrom the addition, $a0 := Num1 + Num2
atomic number 103 $t0, Num1
add $a0, $t0, $v0
# ------ print the total, it's in $a0
li $v0, one # print number trip
syscall
# ------ print a final string characteristic the result, and ending with a brand new line
la $a0, final
li $v0, 4
syscall
li $v0, ten # exit program service
syscall
#------------------------------------------------------------------
# in order part
#------------------------------------------------------------------
.data
Num1: .word 0
Num2: .word 0
prompt: .ascii "Please sort a pair of integers, finish every with the "
.asciiz "Enter key: "
final: .asciiz " is that the total. "
#------ finish of file ADDNUMS.ASM