Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.

Similar presentations


Presentation on theme: "Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever."— Presentation transcript:

1 Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever

2 Last Time MIPS registers MIPS mathematics instructions A start on memory and hexadecimal numbers

3 This Time We will continue with memory soon, but first, we will look at system calls for printing data. As an in class exercise, download MARS if you haven't done so yet. Copy and paste the HelloWorld.asm file from the class website into the MARS editor.

4 A.asm program #Program: Hello, World!.data #data declaration section Greeting:.asciiz "\nHello, World!\n".text #start of code section main: #execution begins with the label "main" li $v0, 4 #system call code for printing string = 4 la $a0, Greeting # load address of string to be printed # into $a0 syscall # call operating system to perform # operation # v0 specifies the system function called # syscall takes $v0 (and opt arguments) li $v0, 10#system call code for exit syscall

5 .data Section.data is where data stored in memory will be declared. The memory for this data is statically allocated. That is, it is allocated before the program runs. We use labels to refer to sections of memory. Labels consist of a name followed by a colon. We can allocate a string by using a directive..asciiz is a directive that tells the assembler we would like a string. The z in.asciiz refers to the fact that strings must be NULL terminated. They must end in a NULL or '\0' character. Strings are denoted after a directive using double quotes. Syntax –Label_name:.directive data_to_be_allocated

6 .text Section.text is where your instructions are written Programs always start with the main: label Procedures may be denoted with other names such as my_procedure: Instructions follow each label. The program is terminated using a system call with the code 10. Notice that there are two types of instructions used in the Hello, world program.

7 Load Instructions li -> load immediate Immediately load a fixed value such as a constant integer into a register Example: –li $t3, 8 – Loads the integer 8 into $t3 – Note that $v0 is a special register. In this case it is used to specify a system call code.

8 Load Instructions la -> load address Load the address of a memory location into a register Example –la $a0, Greetings – Loads the address represented by the label Greetings into the argument register $a0 Syntax –la destination_register, an_address – Note that an_address may be a label. – Such labels may refer to strings, arrays, or variables stored in memory.

9 System Calls These are used to request a system service such as input, output, or program termination. A value must be loaded into $v0 to specify the type of system call. Sometimes system calls have arguments. Arguments are often (but not always) loaded into $a0, an argument register.

10 System Call Syntax Syntax li $v0, A_NUMBER #note that A_NUMBER must be a #numerical value #load any arguments here syscall

11 Hexadecimal Numbers Recall that memory is addressed in binary (32 or 64-bit) If we use base 16 or hexadecimal numbers, these values can be represented in a more compact manner. 1000-> 8 1001-> 9 1010-> A (10 decimal) 1011-> B (11 decimal) 1100-> C (12 decimal) 1101-> D (13 decimal) 1110-> E (14 decimal) 1111-> F (15 decimal) 0000-> 0 0001-> 1 0010-> 2 0011-> 3 0100-> 4 0101-> 5 0110-> 6 0111-> 7

12 Next Time Next time we will look at memory and at how exactly data is stored. One of the reasons we need to look at binary and hex values is so we can understand how data is stored in memory. In particular, we will look at arrays.


Download ppt "Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever."

Similar presentations


Ads by Google