Docsity

Understanding Assembly Commands, Boolean Operations, and Memory in Assembly Programming, Slides of Aeronautical Engineering

Toggle sidebar
bg1
Lecture C7: Assembly programming
Response to 'Muddiest Part of the Lecture Cards'
(58 respondents, out of 74students)
1) The Assembly commands? (10 students)
We can and will review the commands during recitation hours. Please read through the following
"Assembly language handout".
2) I don't understand how to keep all number systems straight. It would help if we had one page about
what they each are & how you convert to and from them? (1 student)
You now have one page and more, take a look at the following document "number representation".
3) The Boolean operations: NOT, AND, OR, XOR? (7 students)
Boolean expressions can be formed much like arithmetic operations, but they contain boolean values
(either True/1 or False/0), boolean variables (which can be assigned the values True/1 or False/0) and
boolean operations.
We use truth tables to define the boolean/logic operations:
The NOT operation is sometimes known as the inverse operation since it simply reverses the state of all
bits. A 0 becomes a 1, and a 1 becomes a 0.
A NOT A
0 1
1 0
Example: if A = NOT B, then B = NOT A
The AND operator takes 2 parameters, the result of "A AND B" results in a 1 if and only if both
operands are 1, otherwise it results in a 0.
A B A AND B
0 0 0
0 1 0
docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Understanding Assembly Commands, Boolean Operations, and Memory in Assembly Programming and more Slides Aeronautical Engineering in PDF only on Docsity!

Lecture C7: Assembly programming

Response to 'Muddiest Part of the Lecture Cards'

(58 respondents, out of 74students)

  1. The Assembly commands? (10 students) We can and will review the commands during recitation hours. Please read through the following "Assembly language handout".

  2. I don't understand how to keep all number systems straight. It would help if we had one page about what they each are & how you convert to and from them? (1 student) You now have one page and more, take a look at the following document "number representation".

  3. The Boolean operations: NOT, AND, OR, XOR? (7 students) Boolean expressions can be formed much like arithmetic operations, but they contain boolean values (either True/1 or False/0 ), boolean variables (which can be assigned the values True/1 or False/0 ) and boolean operations.

We use truth tables to define the boolean/logic operations:

The NOT operation is sometimes known as the inverse operation since it simply reverses the state of all bits. A 0 becomes a 1 , and a 1 becomes a 0.

A NOT A

Example: if A = NOT B, then B = NOT A

The AND operator takes 2 parameters, the result of "A AND B" results in a 1 if and only if both operands are 1 , otherwise it results in a 0.

A B A AND B

The OR operator also takes two operators/parameters, the result of "A OR B" results in a 1 if one or both of the operands are 1 , otherwise it results in 0.

A B A OR B

The XOR operator (the Exclusive Or operator) takes two parameters, results in a 1 if and only if one of the operands are 1. " A XOR B" results in a 0 if both operands equal 0 , or if both operands equal 1.

A B A XOR B

There are a number of different equivalences that are good and helpful to know about, for example: "DeMorgan's Rules" stating that:

ā— NOT (A AND B) is equivalent to ( NOT A) OR ( NOT B) ā— NOT (A OR B) is equivalent ( NOT A) AND ( NOT B)

These equivalences can be verified using the following truth table, where you by comparing column 4 and 7 can verify that NOT (A AND B) is equivalent to ( NOT A) OR ( NOT B).

AND B NOT AND^ (AB) NOT A NOT B ( ORNOT ( NOT^ A ) B)

A B A

addi R2, R2, R3 ;The register R2 gets assigned the value of adding R2's and R3's values together (R2=0h +6h=6h)

addi R4, R1,R2 ;The register R4 gets assigned the value of adding R1's and R2's values together (R4=FEh+6h=4h)

store R4,[FFh] ; Put the value of register R4 at memory location FFh. (M[FFh]=4h)

halt ; Stop the execution of the program.

So, the correct answer on the PRS question was alternative 2: memory location FEh contains 0,and memory location FFh contains 04h.

  1. The second PRS question? (2 students) "What is the result of the following operation? 0110 xor 0000"

For more information about the xor instruction look at question 3) above.

The answer for 0110 xor 0000 is: 0110.

How did we arrive at the answer 0110? We need to perform a bitwise xor between the two four bit numbers 0110 and 0000. Start by doing an xor operation between the bits at position zero 011 0 and 000 0 , 0 xor 0 results in a 0. Next perform the xor operation between bits at position 1: 01 1 0 xor 00 0 0 resulting in a 1. Next perform the xor operation between bits at position two: 0 1 10 xor 0 0 00 resulting in a 1. And finally, perform the xor operation between the most significant bits (bits at position 3 in this case): 0 110 xor 0 000 resulting in a 0. You now have the 4 bits resulting from the bitwise operations just performed, write them up on a line, each bit at its bit position, which gives us the result: 0110.

  1. Why would you ever want to use the value of a memory address in a calculation? (1 student) For example, if you have a string (for example the string "Joeb" as shown in small assembly example below), and want to manipulate the 4th item in that string (in this small example that would be the character 'b'). All information you have is the address for the first character in the string. Lets say that the string "MyName" resides at memory location 20 h in the memory (for this example that means that the ASCII value for 'J' resides in memory position 20h, the ASCII value for 'o' in memory position 21h, the ASCII value for 'e' in position 22h and so on).

; A small example that is going to change the string "Joeb" into being the string "JoeB" by replacing the memory position for character 'b' with the ASCII value of Character 'B' (ASCII for character B = 42h)

jmp 50h ;the PC always starts with value 00, so we have to instantiate the PC with the start address of the instructions

org 20h ; my data area resides at memory position 20h MyName: db "Joeb" ;this is my string

org 50h ;the executable code starts at memory position 50h load R0, MyName ;load register R0 with the address of or string load R1, 3 ;add a 3 to the memory location in R0 (R1's value + 3 = the address of character 'b' in the string) addi R2, R0, R1 ;R2 get the value of 23h = the memory position for character 'b' load R3, 42h ;R3 gets the ASCII value of character 'B' store R3, [R2] ;store R3's value on the memory position where 'b' used to be halt ;stop the execution

  1. How do you know when to store the address into register or the value of address into register? ( student) T he interpretation depends on the instruction.

  2. What are the significance of brackets [ ]? (and similar questions) (2 students) It has to do with: direct or indirect addressing.

For example:

ā— load R1, 42h ; stores the hexadecimal value 42 into register R ā— load R1, [42h] ; assigns the memory contents at address 42h in memory to register R1.

  1. How do I interpret 0xfe? (1 student) A hexadecimal number can, using the assembly language/simulator used in class today, be written in 3

ways:

ā— The number starts with '0x', followed by a sequence of hexadecimal digits ('0' up to '9' and 'A' up to 'F'). For example 0xfe. ā— The number starts with '$', followed by a sequence of hexadecimal digits ('0' up to '9' and 'A' up to 'F'). For example $fe. ā— The number is a sequence of hexadecimal digits ('0' up to '9' and 'A' up to 'F'), but it may not start with a letter. This sequence is followed by an 'h'. A number can always be made to start with a decimal digit by prefixing the number with a '0', so ABh is written as 0ABh. For example feh.

  1. What is db and org? (1 student) db is short for "data byte". It is used to put/store data directly into memory. A data item can be either a number or a string.

Examples:

org 0x20; new_number : db 10d

org 0x10; old_number : db 25d;

The lines after halt are the data area, that is where we declare where our constants should reside in memory. The hex number 10d is placed in memory position 20h , and the 25d is placed in memory position 10h.

  1. Can you differentiate between: R0, R1, R3; 0xfe; [0xfe]; [R1], from the PRS question? ( student) R0, R1, R2, .. are the names of the registers in the CPU

0xfe is a hexadecimal number, FE

[0xFE] was used when we wanted to read the data in memory position FEh

[R1] was used when we wanted to read the data of the memory position, which value was kept in register R

  1. How does the instruction register for the fetch step work? (1 student) The Instruction Register, IR, keeps the bit pattern describing the instruction currently being executed by the CPU. Using our 'Brookshear format', the first 4 bits in IR is the opcode , telling us what operation is performed, the least significant 12 bits show us the operands the operation needs.

  2. The slide for the fetch slide don't seem to match the slide for the decoding instruction? ( student) That is a correct observation, it will be fixed for next version of my lecture notes. Thanks.

the bit pattern: 35A7 = store R5, [A7h]

the bit pattern: 156C = load R5, [6Ch]

  1. If Store R4, [0xff] means R4:=M[ff], isn't R4:=0? because you are storing [0xff] into R4 ( students) If 0 was stored at memory position FF, the register R4 would get assigned value 0.

  2. With such limited commands, how does machine language do anything useful? (1 student) Remember the machine language we looked at today was for the extremely limited and small 'Brookshear processor'. The machine language for e.g., an Intel processor has very many more and more

complex machine instructions.

  1. Why does assigning locations and values have to be so complicated? (1 student) I believe most things/programming languages are complicated if we do not get enough time to learn them and practice using them. Hopefully after some more examples shown in for example recitation it will not seem as complicated any longer.

  2. Is there somewhere to see what readings we could do for lecture/material covered? (1 student) Yes, reading instructions and material are available on the CP web page, which can be reached from the Unified web page.

  3. Is it fair to say that in general X represents the register/memory and [X[ represents the value? ( student) Yes it is.

  4. More on computer architecture? (1 student) Can you be a little bit more specific on what is missing?

  5. What do you suggest I do if I am extremely lost? (1 student) Talk to me after class, send me an email, try and set up a meeting with me, talk to the TAs, attend recitations and office hours, ask TAs about setting up "tutoring sessions", ...

  6. What valuable purpose does it have to work with a machine language instead of using the time we invest into learning Ada95 deeper or even learning other useful high-level programming languages such as C++ or Java? (and similar comments) (2 students) Most aerospace systems involve writing software at both the embedded level as well as the application level. Without having knowledge/understanding about the underlying architecture of a computer system, it is very hard to use the computer in the most efficient and safe way. CP is meant to be an introduction course that will allow all the students of the class to have a common knowledge base on the subject. When it comes to aerospace software Ada is a dominant language. In addition, languages such as C++ and Java do not enforce good programming practice.

  7. "No mud" (11 students) Good :-)