|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Need help with assembly language question
Hello
I need help with an A level computing exam that is coming up very soon. Sometimes in the exam students are asked to write some assembly language code. A typical question is: Using the trace table below write the assembly language equivalent of the following: X=0 While Not (x = 999) Do x = x + 1 End While (In the exam the trace table contains the columns “label”, “opcode” and “operand”) And the answer would be: LDA #0 Loop CMP #999 BEQ Label1 ADD #1 JMP Loop Label1 STA X (the above code is filled in the relevant columns) However last year the exam asked a question that seems different from all the previous years: Using the trace table below write the assembly language equivalent of the following: Count = 0 Repeat x = x + x count = count + 1 until x >= 999 you can assume that the program counter will contain the address of location “start” to execute your code. (then the trace table is partially filled in and the students need to fill in the rest) Code:
Label Opcode Operand comment x 15 Location x contains value 15 count This location is reserved to store the value of count start The model answer provided by the exam board was Start: LDA #0 STA Count Store zero in Count Loop LDA X Load value from location X into accumulator ADD X Add contents of X to accumulator STA X Save contents of accumulator at location labelled X INC Count Increment value in Count CMP #999 Compare contents of accumulator with 999 BLT Loop Conditional branch if contents of accumulator is < 999 Now I understand most of the code except two things: 1, the line “INC count” why isn’t count loaded into a register and then incremented and then after the algorithm is finished it could be stored in the memory location? Is it possible to add to a memory location without loading their value into a register? E.g. ADD memlocation1,#1 2, if it is possible to add to memory locations without having to load their contents into a register then why is value of X loaded into the accumulator and then incremented and the stored back into the memory location for every set of the iteration? Wouldn’t it be better to write STA X just once at the end of the code? I would really appreciate it if someone could help me with this. I need to understand the model answer given by the exam board so that similar answers can be given for future questions. |
|
#2
|
||||
|
||||
|
Quote:
This is very dependent on the CPU model. Most RISC chips don't support any instruction like this, but quite a few CISC chips do. The x86 family has add to memory instructions, for instance. RISC chips usually have only two instructions that deal with memory (LDA and STA). Quote:
Again this is very dependent on the CPU model. Maybe this particular CPU supports INC and DEC instructions directly to a memory location, but not an ADD instruction. In x86 CPU family, they do support ADD to memory instructions, but not all CPUs do this.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
thank you very much for that reply. i did more research on that processor and it helped a lot. thanks.
|
|
#4
|
|||
|
|||
|
Need help to convert a 32 bit mapping into 16 bit
Hi I have a 32 bit mapping code of my friend but I wanna make my code for 16 bit its like a boy moving its arms i hv found made the bit map for that but dont know how to program it if you would like I can send you the 32 bit mapping code if you can help me. I will really appriciate it.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Need help with assembly language question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|