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) Label Opcode Operand comment x 15 Location x contains value 15 count This location is reserved to store the value of count start Code (markup): 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 in the answer 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.
But what was the answer? That's higher level asm than I'm used to, but still...I have the same questions you did. (And it's been several years since I looked at asm at all, so you're ahead of me here).
Yesterday i posted my notes of A-level Assembly language part can be reached here: http://infonote.blogsome.com/2006/01/22/module-3-assembly-languages/