代写COMP2120 Computer Organization Assignment 2调试Python程序

Department of Computer Science

COMP2120 Computer Organization

Assignment 2

Due Date: March 11, 11pm

Consider  a  simple  32-bit  processor  with  the  data  path  as  shown  in fig.  1. The processor has 32 general purpose registers.  There are 3 buses, S1-bus, S2-bus and D-bus connecting the registers for data movement.  The register files has 2 read ports and 1 write port (i.e. it can perform 2 read and 1 write at the same time).

Figure 1: A simplified CPU

The processor has instructions which specifies 3 operands explicitly (namely, 2 source and 1 destination operands).  The leftmost byte of the instruction represents the oper- ation to be performed, such as ADD, SUB etc.  For arithmetic and logic operations, the operands must be in registers.  Hence the 3 bytes will give the addresses of operands in the register file. There will be a direct path connecting these 3 bytes in the IR (Instruc- tion Register) to the address of the register file, so that when you perform read/write on register file, the register specified in these bytes will be accessed.

If the instruction is LOAD or  STORE to load a word from memory to register,  and vice versa, the source operand (LOAD) or destination operand (STORE) refer to a memory address. How to find this address is specified by Addressing Mode. In this machine, for simiplicity, the memory operand byte (source/destination) will always be 1111  1111 (or in hex 0xff), which means that the actual 32-bit memory address will be given in the word following the instruction (see example program below).

The  ALU  has  the  following  operations:   ADD,  SUB,  bitwise  AND,  OR,  and  NOT.  For operations  with  only  one  operand  (e.g.   NOT),  source  operand  1  is  used,  and  source operand 2 is empty.

Finally, there is a branch instruction, which performs conditional or unconditional branch as specified in the cc field of the instruction.  The branch address is specified in the word following the instruction, the same as in LOAD/STORE instruction.

Instruction Format

Arithmetic/Logic Instruction

The instruction format of the machine (except LOAD, STORE and BRANCH):

Opcode

Source

Operand 1

Source

Operand 2

Destination

Operand

The instructions can be categorized into the following types:

Arithmetic Operations

ADD       R1,  R2,  R3   ;  R3  <- R1 + R2

SUB       R1,  R2,  R3   ;  R3  <- R1 - R2

Logical Operations

AND       R1,  R2,  R3   ;  R3  <- R1 and R2

OR         R1,  R2,  R3   ;  R3  <- R1 or R2

NOT        R1,  R3          ;  R3  <- not R1

Data Movement Instruction

MOV       R1,  R3            ;  R3  <- R1

Note that in the NOT and MOV operation, source operand 2 field is not used and will be set as 00000000.

Load/Store Instruction

Moving data from Memory to registers and vice versa.

LD          A,  R3            ;  R3  <- A, A is in memory

ST          R1,  A            ;  A  <- R1, A is in memory

Load instruction:

Opcode

(Load)

00000000

Addressing

Mode

Destination

Operand

Store instruction:

Opcode

(Store)

Source

Operand

Addressing

Mode

00000000

where the addressing mode (how to find the target address) is specified in byte 2 of the instruction. In this machine, only one addressing mode is used, where the target address is given by the word following the LOAD or STORE instruction (Absolute Addressing).  This is specified as 11111111 in that byte.

Control Instruction

Control flow is by using BRANCH instruction.  There are two types of branch instruction — conditional and unconditional Branch. Branch Instruction Format:

Opcode

(Branch)

Condition

Code (cc)

Addressing

Mode

00000000

Conditional branch is based on the result of previous ALU operation, which is store in a flag register.  In this machine, we only use a ZERO flag, which will be set to 1 if the ALU operation results in 0, and set to 0 otherwise.  The target address is specified in the same way as in memory operation.  Similarly, the byte of Addressing Mode is set to 11111111.

The condition code is specified as

Condiation Code (cc)

Instruction

Description

00000000

BR

Unconditaion Branch, always goto

00000001

BZ

Branch if Zero flag is set

00000010

BNZ

Branch if Zero flag is NOT set

Halt Instruction

The HLT instruction is used to stop the program. The other 3 bytes are all 0.

Opcodes

Instruction

Opcode

Instruction

Opcode

Instruction

Opcode

ADD

00000000

OR

00000100

Bcc

00001000

SUB

00000001

MOV

00000101

HLT

00001001

NOT

00000010

LD

00000110

AND

00000011

ST

00000111

Part I: Example Program

The simulator program is given in sim. py.  The code for the SUB and ST instruction is missing.  Study the simulator code carefully, and complete the missing part.

Running the simulator program:

[python3]  sim. py  [-d] prog

If -d option is specified, the program will print out debug information.

The simulator obtains input program from the file prog.

Test you simulator with the following simple program:

LD

P0,R4

0000: 0600ff04

0000003c

LD

P1,R1

0008: 0600ff01

00000040

MOV

R1,R2

0010: 05010002

LD

P2,R3

0014: 0600ff03

00000044

L:      ADD

R4,R1,R4

001C:    00040104

ADD

R1,R2,R1

0020: 00010201

SUB

R3,R1,R5

0024: 01030105

BNZ

L

0028: 0802ff00

0000001c

ST

R4,P

0030: 0704ff00

00000048

HLT

0038: 09000000

P0: . WORD

0

003C:    00000000

P1: . WORD

1

0040: 00000001

P2: . WORD

P:        . WORD

A

0044: 0000000a

0048: 00000000

What does this program do?

Part II: Hand Assemble

Translate the following program into hexadecimal form, and put it in a file named prog2 with the same format as the file prog. Run the simulator by

[python3]  sim. py  [-d] prog2

Write down the final result stored in P. What does the program do?

LD

P0,  R4

LD

P1,  R1

LD

P2,  R2

LD

P3,  R3

L:

ADD

R4,  R2, R4

SUB

R3,  R1, R3

BNZ

L

ST

R4,  P

HLT

P0:

. WORD

0

P1:

. WORD

1

P2:

. WORD

5

P3:

. WORD

4

P:

. WORD

A working simulator (executable pyc file only, without source code) is given to you, so that you can complete this part using this program, if your simulator in Part I is not working.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图