(Your Name) CSC1302 Lab Exp#10 Assembly Language (Page 1 of 5) (Your Name) CSC1302 Lab Exp#10 Assembly Language (Page 2 of 5) Lab 10: Assembly Language Programming To install the full lab Software package, click here. To run the assembler, click Assembler on the main software menu. You will be presented with two panes The left pane is intended for the entry of assembly language source programs. The right pane is a utility area for displaying program listings during compilation, symbol tables, and object code. You also have the following menus: 1. File. From this menu, you can Save and Open assembly language source programs or obtain a New entry pane. You can also print a listing of the program after it assembles. 2. Assembler. From this menu, you can Assemble the source program, View the symbol table that is generated during translation (you will do this in Lab Experience 19), and View the object code. You can also Execute the object code, which actually loads the object code into a von Neumann machine simulator. 3. Instruction Set. From this menu, you can view a dictionary of the instruction set. (Your Name) CSC1302 Lab Exp#10 Assembly Language (Page 3 of 5) 10.1 Adding Two Numbers and Displaying the Result Select Open from the File menu and select the file example1.asm in the EXAMPLES folder. Now click Open. The text of an assembly language source program will appear in the source program pane. Study the code to verify what the program will do. Then choose Assemble from the Assembler menu (see Figure 10.2). A program listing will appear in the utility pane. The listing is just a copy of the source program, with each line numbered for your reference. At the end of the listing, there should be a message that assembly has been completed without syntax errors. The assembler has instantly done what you so painstakingly had to figure out yourself in the last lab section—that is, translate some thoughts expressed in English-like code to the same thoughts expressed in machine code. To see that this is the case, select View Object Code from the Assembler menu. The machine language instructions corresponding to the source code will be displayed in the utility pane, as shown in Figure 10.3. Finally, run the program by selecting Execute from the Assembler menu. A von Neumann machine simulator opens, with the machine code of your program loaded into memory and the source code displayed in the source pane. Run the program in the simulator (by selecting either Run or Step), the current instruction is selected. Run the program. What is the output?: Enter Output Here (Your Name) CSC1302 Lab Exp#10 Assembly Language (Page 4 of 5) 10.2 Some syntax errors You will typically begin by entering a source program by hand or opening it from a file. Assemble is the only option available from the Assembler menu at this point. During assembly, the system displays a program listing and any syntax error messages in the utility pane. Each line of source text is numbered in the listing for easy reference, and an error message appears on the line following the line of code in which the error occurs. Assembly halts at the first error. Error detection is pretty thorough: errors are caught even at the lexical level, such as illegal labels and integer literals that are too large for 16-bit sign magnitude representation. The assembler can generate the following syntax error messages: The program we loaded from a file had no syntax errors. Let's put some syntax errors into it so we can see how the assembler detects them. a. Replace the operand x in the first instruction, load x, with the operand a, then reassemble the program. The assembler should discover that you forgot to provide a data declaration for a. The assembler forces you to keep track of all your data and their initial values by declaring them at the bottom of the program. What is the error message? ______________________________ Correct this error before going on. b. Replace the operator add with the operator multiply in the second instruction. The assembler should discover an unrecognized opcode. What is the error message? ______________________________ Correct this error before going on. c. Replace the number 2 with the number 40000 in the first data declaration. What is the error message? ______________________________ Correct this error before going on. d. Delete the space between add and y in the second instruction. What is the error message? ______________________________ Correct this error before going on. There must be at least one blank space or tab between an operator and its operand. e. Insert a blank line after the second instruction. What is the error message? ______________________________ Correct this error before going on. Assembly language requires an instruction to appear on each line of a program. f. Insert a blank space, followed by subtract, at the end of the second instruction. What is the error message? ______________________________ Don’t correct this error yet. The instruction has three lexical items, the assembler expects the first one to be a label ending with a colon (:). Don’t correct this error yet. g. Oblige the assembler by inserting a colon (:) after add (be sure that there are no blank spaces between the colon and the d. Note the error detected. What is the error message? ______________________________ Now change y to add. The assembler treats subtract as an undeclared data label, which you could remedy by declaring it at the bottom of the program. (Your Name) CSC1302 Lab Exp#10 Assembly Language (Page 5 of 5) 10.03 Making decisions in assembly language Open the file example2.asm and study the program. What does it do? Assemble and execute the program. Does it behave as expected? Modify the program so that it displays the larger of the two numbers, and test it until it behaves correctly. Copy and paste the Assembly source code below: ______________________________ 10.04 Loops in Assembly Language Open the file example3.asm and study the program. What does it do? Assemble and execute the program. Does it behave as expected? Modify the program so that it checks to see that the input data is greater than zero before it starts the loop. If that's not the case, the program should halt with no output. Copy and paste the Assembly source code below: ______________________________ 10.05 Larger/smaller Write pseudocode for a program that allows the user to input two numbers (X and Y) and a code C. If the code has value 1, the program should output the larger of X and Y and otherwise output the smaller. Now convert your pseudocode to an assembly language program. Enter the program into the lab software assembler. Assemble the program and execute it with different input data. Copy and paste the Assembly source code below: ______________________________