Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

I am stuck on a homework problem regarding assembly code

Status
Not open for further replies.

upopads

Newbie level 3
Newbie level 3
Joined
Sep 13, 2009
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,340
This Question is for my class in Embedded microcontrollers in the book Fundamentals of Microcontrollers and applications in Embedded systems by Ramesh S. Gaonkar it is chapter 5 on branch operations. I am at a loss as to what the code is asking, i need help in solving the problem specifically with understanding what Cyl means in the code.

Question:
5.22 How many times is LOOP1 executed in the following instructions?

MOVLW 0x32
MOVWF REG2,0
LOOP1: DECF REG2, 1-4 Cyl
BNZ LOOP1 - 8/4 Cyl

Other questions that are confusing to me:

How many times is LOOP1 executed if BNZ is changed to BZ

How many times is LOOP1 executed if the instructions BNZ is changed to BNC

How many times is LOOP1 executed if the instruction DECF REG2,1 is changed to DECF REG2, 0
 

Hi,

Will try and answer you first question, although I do not understand the use / meaning of the 1-4Cyl or 8/4 Cyl myself ( somewhat strange for a beginners course ? )


Code:
MOVLW 0x32                  ; loads W with the hex value 32

MOVWF REG2,0                ; moves the value in W to, and stores it in the variable REG2 ,  the ,0 denotes the REG2 is in Access Ram
                                 
LOOP1  DECF REG2, 1-4 Cyl   ; This decrements the value held in REG2 by hex 01
                            ; the new value is saved in REG2
                            ; the result of the DECF operation then changes the respective bits of the STATUS register.

BNZ LOOP1 - 8/4 Cyl        ;  Here the STATUS reg bit Zero is tested, if the result is Zero then go out of the routine,  if not go                                ; round to LOOP1 and decrement the value REG2 again.


If you can follow that decrementing loop ok then you should be able to answer those remaining questions yourself, although the last one is a bit of a trick.

Are you running Mplab and its Simulator function - here you can set the code running and step though it one instruction at a time and observe the variable and Status registers changing as they execute.
 

Assembly language is a new thing for me so I'm a beginner but what you said has given me much more clarification than what i originally had because the book really doesn't explain the Cyl instruction at all. Engineering unfortunately isn't particularly strong at my college and i am electrical.

Question:
5.22 How many times is LOOP1 executed in the following instructions?

So from what i understand the answer is 50 because the conversion of 32Hex to decimal is 50 and we are decrementing the decimal value by one.

MOVLW 0x32
MOVWF REG2,0
LOOP1: DECF REG2, 1-4 Cyl
BNZ LOOP1 - 8/4 Cyl


Other questions that are confusing to me:

How many times is LOOP1 executed if BNZ is changed to BZ?

I think 49 because when Z = 1 end loop

How many times is LOOP1 executed if the instructions BNZ is changed to BNC

I think 50-32=18 times because 11111 base 2 converted to decimal is 32 and since 110001 is 50 in decimal which is 32 in Hex the carry occurs after the last transition from the 5th digit to the 6th digit in the equation.


How many times is LOOP1 executed if the instruction DECF REG2,1 is changed to DECF REG2, 0

Probably zero because the access bank memory isn't being used or something but i have to research this one a bit further.

Added after 7 minutes:

I do have MP lab on my computer and it complies however i cannot run code correctly to execute the software i am using to demo problems. The power point presentation designed to help us program our micro controllers using Assembly doesn't explain how to run a simple program using the software correctly

Added after 15 seconds:

I do have MP lab on my computer and it complies however i cannot run code correctly to execute the software i am using to demo problems. The power point presentation designed to help us program our micro controllers using Assembly doesn't explain how to run a simple program using the software correctly
 

Hi,




Question:
5.22 How many times is LOOP1 executed in the following instructions?

So from what i understand the answer is 50 because the conversion of 32Hex to decimal is 50 and we are decrementing the decimal value by one.

Sounds right to me.


Other questions that are confusing to me:

How many times is LOOP1 executed if BNZ is changed to BZ?

I think 49 because when Z = 1 end loop

I don't know what you have been taught or what info you have, but if you download the datasheet for your chip, towards the back of the pdf you will see a section called the ' Instruction Set Summary' this lists all the instructions and what their actions are.

Again if you have built the project ok then you should be able to run the Debugger, Sim which lets you step through each instruction and watching the registers change as they do so - Mplab Help should guide you through running it - see attched pdf picture.



How many times is LOOP1 executed if the instructions BNZ is changed to BNC

I think 50-32=18 times because 11111 base 2 converted to decimal is 32 and since 110001 is 50 in decimal which is 32 in Hex the carry occurs after the last transition from the 5th digit to the 6th digit in the equation.

Again first look at what the instruction is doing, this time it is testing the Carry flag or bit of the Status register - so you need to understand what changes the Carry flag before you can answer that question.


How many times is LOOP1 executed if the instruction DECF REG2,1 is changed to DECF REG2, 0

Probably zero because the access bank memory isn't being used or something but i have to research this one a bit further.

The 0 or 1 are defining where REG2 is located - understanding the meaning of the Banks and Access Ram can be a little confusing to start with - this is really a point you should ask you tutor for clarification on - again the Microchip datasheet for your chip does give details of this - although perhaps a little difficult to grasp as Microchips description often leave you more confused than before you started reading it ..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top