Sie sind auf Seite 1von 7

Q.

1
Ans:
AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0x37AF

; Move 0x37AF to lowe r byte of R1

STOP

LSR R3 , R1 , #1 ; Logical shift right by 1 bits

LSR R4 , R3 , #3 ; Logical shift right by 3 bits

LSRS R2 , R4 , #12 ; Logical shift right by 12 bits without flags update

B STOP

END ; End of the program

Q.2
Ans:
AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R3 , #0x395A62

; Move 395A62 to lowe r byte of R3

STOP

ASR R5 , R3 , #1 ; Arithmetic shift right by 1 bits

ASR R6 , R5 , #5 ; Arithmetic shift right by 5 bits


ASRS R4 , R6 , #15 ; Arithmetic shift right by 15 bits with flags update

B STOP

END ; End of the program

Q.03
Ans:
First create the 2's complement bit pattern for -321 by flipping the bit pattern of 321 and
adding 1:

0011 0010 0001 becomes 1100 1101 1110 + 1 becomes 1100 1101 1111=CDF

AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0xCDF

; Move 0xCDF to lowe r byte of R1

STOP

LSR R2 , R1 , #1 ; Logical shift right by 1 bits

LSR R3 , R2 , #3 ; Logical shift right by 3 bits

LSRS R4 , R3 , #12 ; Logical shift right by 12 bits without flags update

ASR R5 , R4 , #1 ; Arithmetic shift right by 1 bits

ASR R6 , R5 , #5 ; Arithmetic shift right by 5 bits

ASRS R7 , R6 , #15 ; Arithmetic shift right by 15 bits with flags update

B STOP

END ; End of the program


Q.04
Ans:
AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0xA642

; Move 0xA642 to lowe r byte of R1

MOV R3 , #0x8

STOP

MUL R2 , R1 , R3

B STOP

END ; End of the program

Q.05
Ans:
First create the 2's complement bit pattern for -458 by flipping the bit pattern of 458 and
adding 1:

0100 0101 1000 becomes 1011 1010 0111 + 1 becomes 0 1011 1010 1000 =BA8

AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0xBA8

; Move 0xBA8to lowe r byte of R1

MOV R2 , #0x1CA
; Move 0x1CA to lowe r byte of R1

STOP

LSL R3 , R1 , #1 ; Logical shift left by 1 bits

LSL R4 , R2 , #3 ; Logical shift left by 3 bits

LSLS R5 , R4 , #12 ; Logical shift left by 12 bits without flags update

B STOP

END ; End of the program

Q.06
Ans:
AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0xBA8

; Move 0xBA8to lowe r byte of R1

MOV R2 , #0x1CA

; Move 0x1CA to lowe r byte of R1

STOP

LSL R3 , R1 , #1 ; Logical shift left by 1 bits

LSL R4 , R2 , #3 ; Logical shift left by 3 bits

LSLS R5 , R4 , #12 ; Logical shift left by 12 bits without flags update

B STOP

END ; End of the program


Q.07
Ans:
The two bits on the left of the pattern are guaranteed to be zero; the other bits are not changed.

You might have hastily said that the net result is no change. But if there are one-bits at the left
(high order) end of the pattern they will be lost.

MIPS also has a shift right logical instruction. It moves bits to the right by a number of
positions less than 32. The high-order bit gets zeros and the low-order bits are discarded.

If the bit pattern is regarded as an unsigned integer, or a positive two's comp. integer, then a
right shift of one bit position performs an integer divide by two. A right shift by N positions
performs an integer divide by 2N.

The "trick" of dividing an integer by shifting should not be used in place of the MIPS
arithmetic divide instruction (which will be covered in a few chapters). If you mean "divide"
that is what you should write. But the trick is often used in hardware, and sometimes pops
up in odd software uses, so you should know about it.

Q.08

Ans:

Q.09:

Ans:

First create the 2's complement bit pattern for 0xC5AF2 by flipping the bit pattern of
0xC5AF2 and adding 1:

1100 0101 1010 1111 0010 becomes 0011 1010 0101 0000 1101 + 1 becomes 0 1011 1010
1000 = 3A50E

AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main
MOV R1 , #0x3A50E

; Move 0x3A50E to lowe r byte of R1

MOV R2 , #0x8

; Move 0x8 to lowe r byte of R2

STOP

MUL R3 , R2 , R1 ;multiplication of R1 and R2

B STOP

END ; End of the program

Q.10
Ans:
AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0xA964

; Move 0xA964 to lowe r byte of R1

MOV R9, #0x8

STOP

LSR R3 , R2 , #1

ASR R4, R3, #1

LSL R5, R4, #1

ROR R6, R5, #1

RRX R6, R9

B STOP

END ; End of the program


Q.11
Ans:
AREA my_code, CODE , READONLY

EXPORT __main

ENTRY

__main

MOV R1 , #0xD29D1C8B

; Move 0xD29D1C8B to lowe r byte of R1

MOV R9, #0x8

STOP

LSRS R3 , R2 , #1

ASRS R4, R3, #1

LSLS R5, R4, #1

RORS R6, R5, #1

RRXS R6, R9

B STOP

END ; End of the program

Q.12
Ans:

Das könnte Ihnen auch gefallen