BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »
Showing posts with label Computer Language. Show all posts
Showing posts with label Computer Language. Show all posts

Saturday, 15 December 2012

Computer Language : Usage of Syscall


Input / Output : Usage of Syscall

·         Assembly programs request a service by loading the system call (syscall) instruction.



Format  :


·        System services.
Service
System Call Code
Arguments
Result
print_int
1
$a0 = integer
print_float
2
$f12 = float
print_double
3
$f12 = double
print_string
4
$a0 = string
read_int
5
integer (in $v0)
read_float
6
float (in $f0)
read_double
7
double (in $f0)
read_string
8
$a0 = buffer, $a1 = length
sbrk
9
$a0 = amount
address (in $v0)
exit
10
print_character
11
$a0 = character
read_character
12
character (in $v0)
open
13
$a0 = filename,
file descriptor (in $v0)
$a1 = flags, $a2 = mode
read
14
$a0 = file descriptor,
bytes read (in $v0)
$a1 = buffer, $a2 = count
write
15
$a0 = file descriptor,
bytes written (in $v0)
$a1 = buffer, $a2 = count
close
16
$a0 = file descriptor
0 (in $v0)
exit2
17
$a0 = value

Example :
a.) exit


b.) Get a number and store it


c. ) Print result from $t2


By : Wong Poh Ling    B031210033

Computer Language : Logical Operation


Logical Operation



Logical
and
and $1,$2,$3
$1 = $2 & $3
3 register operands; Logical AND
or
or $1,$2,$3
$1 = $2 | $3
3 register operands; Logical OR
not
nor $1,$1,$0
0=1/ 1=0
convert 1 to 0
convert 0 to 1
and immediate
andi $1,$0,100
$1 = 100
Logical AND register, constant
or immediate
ori $1,$0,100
$1 =100
Logical OR register, constant
shift left logical
sll $1,$2,10
$1 = $2 << 10
Shift left by constant
shift right logical
srl $1,$2,10
$1 = $2 >> 10
Shift right by constant

·         Example :   1.)                  sll   $t0,$t0,16                     srl   $t0,$t0,24
 0001 0010 0011 0100 0101 0110 0111 1000

solution : 
0101 0110 0111 1000 0000 0000 0000 0000      #sll
0000 0000 0000 0000 0000 0000 0101 0110      #srl


2.)         if     $t1 contains    00000000 00000000 00000000 00101100
                    $t2  contains   00000000 00000000 00000000 00001010

                What is the final content of $8 after this instruction is performed?
1.        and  $t0, $t1, $t2          # reg  $t0 = $t1 & $t2
2.        or   $t0, $t1, $t2          # reg  $t0 = $t1 & $t2

Solution:
For the AND operation, $t0 contains
      00000000 00000000 00000000 00001000
For the OR operation, $t0 contains
      00000000 00000000 00000000 00101110

By : Chong Cai Ning      B031210080

Computer Language : Arithmetic Operation


Arithmetic Operation
·         Arithmetic operations are performed on 32-bits numbers held in the general purpose registers (32-bit each)
·         Two types of instruction are included in this operation :
1.      Signed arithmetic : may generate an overflow
2.      Unsigned arithmetic : never generate an overflow
Category
Instruction
Example
Meaning

                             

Arithmetic


add
add $1,$2,$3
$1 = $2 + $3
add immediate
addi $1,$2,100
$1 = $2 + 100
add unsigned
addu $1,$2,$3
$1 = $2 + $3
add immediate unsigned
addi $1,$2,100
$1 = $2 + 100
subtract
sub $1,$2,$3
$1 = $2 - $3
subtract unsigned
subi $1,$2,$3
$1 = $2 - $3
multiplication
mult $1,$2
 mflo $3
$1*$2
quotient store in $3
division
div $1,$2
mflo $3
mfhi $4
$1/$2
quotient store in $3
remainder store in $4

Example :
a.)    f = (g + h) - (i + j);                        #Assume f, g, h, i, j uses $s0, .. $s4

add $s0,$s1,$s2       # f = g + h
add $t0,$s3,$s4       # t0 = i + j
sub $s0,$s0,$t0       # f=(g+h)-(i+j)

b.)    a = c/d
a = c%d                                    #Assume a,b,c,d uses $s0…..$s4

div     $s2, $s3             # lo=c/d , hi=c%d
mflo  $s0                     #store quotient in $s0
mfhi  $s1                     #store remainder in $s1

By : Chong Lee Man   B031210367