Jump to content
Bob Man Homework

Computer Science Homework Question

Recommended Posts

9 minutes ago, Bob Man Homework said:

I need some help with part b thanks

What machine code/assembler conditional branch instructions do you know.. ?

ps. People reading this thread and seeing your screen-shot have no idea what has been shown in Section 5.2.4...

 

Edited by Sensei

Share this post


Link to post
Share on other sites
Quote

Like to end the sequence if the condition isn't met? or is that not needed 

There is no END in assembly some processors do allow you to use it though. If you would like to use END it should be at the end of the source file not in the middle of a conditional and there should only be one instance of it.

Ending an assembly program should consist of a jump or goto to the end of the source code file since assembly is essentially what an OS is written in the only way to really end it is to shutdown the computer.

Share this post


Link to post
Share on other sites
1 hour ago, fiveworlds said:

There is no END in assembly some processors do allow you to use it though. If you would like to use END it should be at the end of the source file not in the middle of a conditional and there should only be one instance of it.

Ending an assembly program should consist of a jump or goto to the end of the source code file since assembly is essentially what an OS is written in the only way to really end it is to shutdown the computer.

I changed it to HALT thats fine right? 

Share this post


Link to post
Share on other sites

@fiveworlds

I hope so you (and everybody reading it) understand it's not the real machine code/assembler, but just fake machine code (aka "pseudocode"), made just for purpose of exercise..

 

Edited by Sensei

Share this post


Link to post
Share on other sites
Quote

I hope so you (and everybody reading it) understand it's not the real machine code/assembler, but just fake machine code (aka "pseudocode"), made just for purpose of exercise..

Yeah, but there is no reason to not do it properly. Modern instruction sets don't use exit.

https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf
 

Quote

HALT thats fine right? 

 

Would you just press the off button on your computer all the time? There should always be a shutdown process so you should be jumping to that.

Edited by fiveworlds

Share this post


Link to post
Share on other sites
8 hours ago, fiveworlds said:

Ending an assembly program should consist of a jump or goto to the end of the source code file since assembly is essentially what an OS is written in the only way to really end it is to shutdown the computer.

There is absolutely nothing wrong with showing the end of execution in an example program (especially one using pseudocode) by using a HALT, EXIT, END or similar instruction.

The other common way of showing that the processor will stop executing is to use a branch (or jump-relative) 0 - this means that the processor will just keep executing the same instruction all the time. (In some processors this can be detected as, for example, a breakpoint.)

In a real piece of code to be executed, then the correct way to end the code depends on the environment it is being run in. If there is no OS, then any of the above approaches is OK. If there is an OS, then it may be a return or breakpoint is the right way to end the code.

assembly is essentially what an OS is written in

No modern OS is written in assembler. They are nearly always written in C, possibly with small bits of code written in assembler where specific short code sequences are required.

the only way to really end it is to shutdown the computer.

That really isn't true.

1 hour ago, fiveworlds said:

There should always be a shutdown process so you should be jumping to that.

This is just an introduction to the types of operations available in a typical processor. You are introducing all sorts of unnecessary complications.

10 hours ago, Bob Man Homework said:

I need some help with part b thanks

The only problem I can see here is that you have:

LOAD 200

MOVE 200, 100

The first instruction loads the value from address 200 (the value 1) into the processors register. The second instruction copies the value from address 200 to address 10. So you don't need the first instruction. 

You could do:

LOAD 200

STORE 100

but that is one extra instruction so simpler just to use the MOVE.

Edited by Strange

Share this post


Link to post
Share on other sites

I remember the day when we used to have

 

STOP

END

EXIT

 

And each had a different reason to be there.

Share this post


Link to post
Share on other sites
On 10/20/2018 at 6:19 AM, Strange said:

There is absolutely nothing wrong with showing the end of execution in an example program (especially one using pseudocode) by using a HALT, EXIT, END or similar instruction.

The other common way of showing that the processor will stop executing is to use a branch (or jump-relative) 0 - this means that the processor will just keep executing the same instruction all the time. (In some processors this can be detected as, for example, a breakpoint.)

In a real piece of code to be executed, then the correct way to end the code depends on the environment it is being run in. If there is no OS, then any of the above approaches is OK. If there is an OS, then it may be a return or breakpoint is the right way to end the code.

assembly is essentially what an OS is written in

No modern OS is written in assembler. They are nearly always written in C, possibly with small bits of code written in assembler where specific short code sequences are required.

the only way to really end it is to shutdown the computer.

That really isn't true.

This is just an introduction to the types of operations available in a typical processor. You are introducing all sorts of unnecessary complications.

The only problem I can see here is that you have:

LOAD 200

MOVE 200, 100

The first instruction loads the value from address 200 (the value 1) into the processors register. The second instruction copies the value from address 200 to address 10. So you don't need the first instruction. 

You could do:

LOAD 200

STORE 100

but that is one extra instruction so simpler just to use the MOVE.

Thanks, I think I messed up when just asking for help I should have stated much more. Yes this is pseuducode, I don't really think the main point of this question, which is from the most basic computer science course is to go fully in depth. It's more of use what's given and do this, which is create the code in the "machine language" given to us. I'm sure if we actually had to do this it would be more complicated not all things would match in this example vs a real working one, which is why the course is not intended to be practical real world use. Sorry for all the confusion I'll clearly state the stuff at the beginning next time. The course is more so just to learn some basics and set down a starting point. I personally think putting another JUMP command along with the other JUMP command would have been better and let that JUMP go to HALT, instead I just inserted HALT in but we'll see. I'll get back to this post if I remember to about what I get.

Thanks for all the input and help, Sensei, fiveworlds, strange and studiot. 

Share this post


Link to post
Share on other sites
37 minutes ago, Bob Man Homework said:

The course is more so just to learn some basics and set down a starting point. I personally think putting another JUMP command along with the other JUMP command would have been better and let that JUMP go to HALT, instead I just inserted HALT in but we'll see. I'll get back to this post if I remember to about what I get.

After rereading your code, and revising fiveworlds comment, I see now why he could have objections (or rather advice), but he didn't mention alternative.. JUMPLT (in the real MIPS/Motorola code "BLT" = "Branch on Less Than"), together with EXIT, could be replaced by reverse of it i.e. JUMPGE (in the real code "BGE" = "Branch on Greater or Equal"). 33 line is right below EXIT, so after change it will be at 32 line (EXIT will be gone), and branch will skip entire section..

 

Edited by Sensei

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.