Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Branch Instructions and Immediate Addressing Mode - Lab 3 | ECEN 3213, Lab Reports of Electrical and Electronics Engineering

Material Type: Lab; Subject: Electrical and Computer Engineering ; University: Oklahoma State University - Stillwater; Term: Spring 2005;

Typology: Lab Reports

Pre 2010

Uploaded on 03/19/2009

koofers-user-jta
koofers-user-jta 🇺🇸

5

(1)

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Branch Instructions and Immediate Addressing Mode - Lab 3 | ECEN 3213 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity! ECEN 3213 Spring 2005 Lab 3 Due in Lab Section, Feb. 7, 9 Objective. Gain familiarity with 6811 branch instructions and immediate addressing mode. Discussion. We will continue to use the microcomputer window in the TExaS simulator to look inside the microcomputer chip to understand how the microcomputer works. A branch instruction allows a change in the normal program flow. The PC register inside the microcomputer keeps track of the address of the next instruction in memory. Every time an instruction is executed, the PC gets incremented by the instruction length so that the next sequential instruction will be next. Branches allow a condition to be specified by the programmer which will determine where to find the next instruction. If the condition is true (a taken branch), then the next instruction will be at the address in the operand field. If the condition is false (a not taken branch), then the next instruction will be the at the next sequential address as usual. For example, lda XX bmi minus if x >= 0 suba #$0A x = x - 10 minus adda #$07 x = x + 7 When XX is negative (minus), the branch to the minus label is taken so that the suba instruction is not executed. When XX is positive (note: zero is treated as positive since it has a leading 0 bit), the branch is not taken and the next instruction executed is the suba instruction. The branch condition is determined by how the flag bits are set by the arithmetic and logi- cal instructions we studied in lab 2. The most frequently used flag bits are the N, Z, V and C flags. The various types of branch instructions use the flags in different combinations. For example, bmi (bpl) branches when N = 1 (0), and beq (bne) branches when Z = 1 (0). Other branch instructions use much more complicated functions of the flags to determine the branch condition. These more complex branches have been included in the instruction set to facilitate comparison operations between signed numbers and between unsigned numbers. Suppose there are two numbers in the a,b registers that are to be compared. First subtract b from a to set the flags and then branch. The compare instructions are just subtraction instructions that just set flags and do not change the a,b registers. The branch ECEN 3213 Spring 2005 Lab 3 January 27, 2005 page 1 of 4 instructions should immediately follow the subtract or compare instructions. Here are some examples. cba compare a and b beq equal a = b blt less a < b (signed) blo lessu a < b (unsigned) ble lseq a <= b (signed) bls lsequ a <= b (unsigned) bgt grt a > b (signed) bhi grtu a > b (unsigned) bge gteq a >= b (signed) bhs gtequ a >= b (unsigned) In lab 2, we stored constants in ROM and specified the address of the data as part of the instruction. Alternatively, the constant data itself can be made part of the instruction. This is called immediate addressing mode. ldb #3 loads $03 into b lda #$07 loads $07 into a Program Specifications. Write assembly code for the following pseudo-code. A = 0; B = 0; loop: oldA = A; oldB = B; if (A = B) { A = oldA + oldB - 7; B = oldA + oldB +10; } else { A = oldA - oldB + 10; B = oldB - oldA - 7; } go to loop; where A, B are signed single byte variables. Procedure. 1. Enter your program in the program window and assemble it. Remember that you must open a microcomputer window in order to assemble your code. 2. In the microcomputer window, click on registers and then add the variables A, B, to the display. Use “h” format for the byte variables and constants and “H” (default) format for the word variable and constants. 3. Run your program and make sure it stops without getting any error messages. 4. Add a breakpoints after the comparison of A and B but before the branch.ECEN 3213 Spring 2005 Lab 3 January 27, 2005 page 2 of 4
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved