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r
w
i
s
e
,
 
s
t
o
p
 
p
r
o
g
r
a
m
 
e
x
e
c
u
t
i
o
n
 
Y
8
6
 
C
o
d
e
 
v
s
 
X
8
6
 
C
o
d
e
 
C
C
o
o
d
d
i
i
n
n
g
g
 
 
E
E
x
x
a
a
m
m
p
p
l
l
e
e
F
i
n
d
 
n
u
m
b
e
r
 
o
f
 
e
l
e
m
e
n
t
s
 
i
n
 
n
u
l
l
-
t
e
r
m
i
n
a
t
e
d
 
l
i
s
t
int len1(int a[]);
 
 
Y
8
6
 
C
o
d
e
 
G
e
n
e
r
a
t
i
o
n
 
E
x
a
m
p
l
e
 
F
i
r
s
t
 
T
r
y
W
r
i
t
e
 
t
y
p
i
c
a
l
 
a
r
r
a
y
 
c
o
d
e
 
 
 
 
 
 
 
 
 
 
P
r
o
b
l
e
m
H
a
r
d
 
t
o
 
d
o
 
a
r
r
a
y
 
i
n
d
e
x
i
n
g
 
o
n
Y
8
6
S
i
n
c
e
 
d
o
n
t
 
h
a
v
e
 
s
c
a
l
e
d
a
d
d
r
e
s
s
i
n
g
 
m
o
d
e
s
/* Find number of elements in
   null-terminated list */
int len1(int a[])
{
  int len;
  for (len = 0; a[len]; len++)
 
;
  return len;
}
L5:
 
incl  %eax
 
cmpl  $0, (%edx,%eax,4)
 
jne
 
L5
 
Y
8
6
 
C
o
d
e
 
G
e
n
e
r
a
t
i
o
n
 
E
x
a
m
p
l
e
 
#
2
 
S
e
c
o
n
d
 
T
r
y
W
r
i
t
e
 
w
i
t
h
 
p
o
i
n
t
e
r
 
c
o
d
e
 
 
 
 
 
 
 
 
 
 
R
e
s
u
l
t
D
o
n
t
 
n
e
e
d
 
t
o
 
d
o
 
i
n
d
e
x
e
d
a
d
d
r
e
s
s
i
n
g
/* Find number of elements in
   null-terminated list */
int len2(int a[])
{
  int len = 0;
  while (*a++)
 
len++;
  return len;
}
.L11:
 
incl
 
%ecx
 
movl
 
(%edx), %eax
 
addl
 
$4, %edx
 
testl
 
%eax, %eax
 
jne
 
.L11
 
Y
8
6
 
C
o
d
e
 
G
e
n
e
r
a
t
i
o
n
 
E
x
a
m
p
l
e
 
#
3
 
I
A
3
2
 
C
o
d
e
S
e
t
u
p
 
Y
8
6
 
C
o
d
e
S
e
t
u
p
len2:
 
pushl %ebp
 
movl %esp, %ebp
 
 
 
 
 
movl 8(%ebp), %edx
 
movl $0, %ecx
 
movl (%edx), %eax
 
addl
 
 $4, %edx
 
testl %eax, %eax
 
je
 
.L13
len2:
 
pushl %ebp
 
# Save %ebp
 
rrmovl %esp, %ebp
 
# New FP
 
pushl %esi   
 
# Save
 
irmovl $4, %esi
 
# Constant 4
 
pushl %edi
 
# Save
 
irmovl $1, %edi
 
# Constant 1
 
mrmovl 8(%ebp), %edx
 
# Get a
 
irmovl $0, %ecx
  
# len = 0
 
mrmovl (%edx), %eax
  
# Get *a
 
addl %esi, %edx
  
# a++
 
andl %eax, %eax
  
# Test *a
 
je Done     # If zero, goto Done
 
N
e
e
d
 
c
o
n
s
t
a
n
t
s
 
1
 
&
 
4
S
t
o
r
e
 
i
n
 
c
a
l
l
e
e
-
s
a
v
e
 
r
e
g
i
s
t
e
r
s
 
U
s
e
 
a
n
d
l
 
t
o
 
t
e
s
t
 
r
e
g
i
s
t
e
r
 
Y
8
6
 
C
o
d
e
 
G
e
n
e
r
a
t
i
o
n
 
E
x
a
m
p
l
e
 
#
4
 
I
A
3
2
 
C
o
d
e
L
o
o
p
 
&
 
E
x
i
t
 
Y
8
6
 
C
o
d
e
L
o
o
p
 
&
 
E
x
i
t
.L11:
 
incl %ecx
 
movl (%edx), %eax
 
addl $4, %edx
 
testl %eax, %eax
 
jne .L11
 
.L13:
 
movl %ecx, %eax
 
 
 
leave
 
 
ret
Loop:
 
addl %edi, %ecx
  
# len++
 
mrmovl (%edx), %eax
  
# Get *a
 
addl %esi, %edx
  
# a++
 
andl %eax, %eax
  
# Test *a
 
jne Loop     # If !0, goto Loop
 
Done:
 
rrmovl %ecx, %eax
 
# return len
 
popl %edi    # Restore %edi
 
popl %esi    # Restore %esi
 
rrmovl %ebp, %esp # Restore SP
 
popl %ebp         # Restore FP
 
ret
 
Y
8
6
 
C
o
d
e
 
G
e
n
e
r
a
t
i
o
n
 
E
x
a
m
p
l
e
 
#
5
 
I
A
3
2
 
C
o
d
e
F
i
n
i
s
h
 
Y
8
6
 
C
o
d
e
F
i
n
i
s
h
.L13:
 
movl %ecx, %eax
 
 
 
leave
 
 
ret
Done:
 
rrmovl %ecx, %eax
 
# return len
 
popl %edi    # Restore %edi
 
popl %esi    # Restore %esi
 
rrmovl %ebp, %esp # Restore SP
 
popl %ebp         # Restore FP
 
ret
 
Y
8
6
 
S
a
m
p
l
e
 
P
r
o
g
r
a
m
 
S
t
r
u
c
t
u
r
e
 
#
1
 
P
r
o
g
r
a
m
 
s
t
a
r
t
s
 
a
t
a
d
d
r
e
s
s
 
0
M
u
s
t
 
s
e
t
 
u
p
 
s
t
a
c
k
W
h
e
r
e
 
l
o
c
a
t
e
d
P
o
i
n
t
e
r
 
v
a
l
u
e
s
M
a
k
e
 
s
u
r
e
 
d
o
n
t
o
v
e
r
w
r
i
t
e
 
c
o
d
e
!
M
u
s
t
 
i
n
i
t
i
a
l
i
z
e
 
d
a
t
a
init:
 
# Initialization
 
. . .
 
call Main
 
halt
 
 
.align 4 
 
# Program data
array:
 
. . .
 
Main:
 
# Main function
 
. . .
 
call len2
   . . .
 
len2:
 
# Length function
 
. . .
 
 
.pos 0x100
 
# Placement of stack
Stack:
 
Y
8
6
 
P
r
o
g
r
a
m
 
S
t
r
u
c
t
u
r
e
 
#
2
 
P
r
o
g
r
a
m
 
s
t
a
r
t
s
 
a
t
a
d
d
r
e
s
s
 
0
M
u
s
t
 
s
e
t
 
u
p
 
s
t
a
c
k
M
u
s
t
 
i
n
i
t
i
a
l
i
z
e
 
d
a
t
a
C
a
n
 
u
s
e
 
s
y
m
b
o
l
i
c
n
a
m
e
s
init:
 
irmovl Stack, %esp  # Set up SP
 
irmovl Stack, %ebp  # Set up FP
 
call Main           # Execute main
 
halt                # Terminate
 
# Array of 4 elements + terminating 0
 
.align 4
array:
 
.long 0x000d
 
.long 0x00c0
 
.long 0x0b00
 
.long 0xa000
 
.long 0
 
Y
8
6
 
P
r
o
g
r
a
m
 
S
t
r
u
c
t
u
r
e
 
#
3
 
S
e
t
 
u
p
 
c
a
l
l
 
t
o
 
l
e
n
2
F
o
l
l
o
w
 
I
A
3
2
 
p
r
o
c
e
d
u
r
e
 
c
o
n
v
e
n
t
i
o
n
s
P
u
s
h
 
a
r
r
a
y
 
a
d
d
r
e
s
s
 
a
s
 
a
r
g
u
m
e
n
t
Main:
 
pushl %ebp
 
rrmovl %esp,%ebp
 
irmovl array,%edx
 
pushl %edx      
 
# Push array
 
call len2
 
# Call len2(array)
 
rrmovl %ebp,%esp
 
popl %ebp
 
ret
 
A
s
s
e
m
b
l
i
n
g
 
Y
8
6
 
P
r
o
g
r
a
m
 
G
e
n
e
r
a
t
e
s
 
o
b
j
e
c
t
 
c
o
d
e
 
f
i
l
e
 
l
e
n
.
y
o
A
c
t
u
a
l
l
y
 
l
o
o
k
s
 
l
i
k
e
 
d
i
s
a
s
s
e
m
b
l
e
r
 
o
u
t
p
u
t
unix> yas len.ys
0x000:              | 
 
.pos 0
0x000: 30f400010000 | init:
 
irmovl Stack, %esp  # Set up stack pointer
0x006: 30f500010000 | 
 
irmovl Stack, %ebp  
 
# Set up base pointer
0x00c: 8028000000   | 
 
call Main
  
# Execute main program
0x011: 00           | 
 
halt
   
# Terminate program
                    |
                    | # Array of 4 elements + terminating 0
0x014:              | 
 
.align 4
0x014:              | array:
0x014: 0d000000     | 
 
.long 0x000d
0x018: c0000000     | 
 
.long 0x00c0
0x01c: 000b0000     | 
 
.long 0x0b00
0x020: 00a00000     | 
 
.long 0xa000
0x024: 00000000     | 
 
.long 0
 
S
i
m
u
l
a
t
i
n
g
 
Y
8
6
 
P
r
o
g
r
a
m
 
I
n
s
t
r
u
c
t
i
o
n
 
s
e
t
 
s
i
m
u
l
a
t
o
r
C
o
m
p
u
t
e
s
 
e
f
f
e
c
t
 
o
f
 
e
a
c
h
 
i
n
s
t
r
u
c
t
i
o
n
 
o
n
 
p
r
o
c
e
s
s
o
r
 
s
t
a
t
e
P
r
i
n
t
s
 
c
h
a
n
g
e
s
 
i
n
 
s
t
a
t
e
 
f
r
o
m
 
o
r
i
g
i
n
a
l
unix> yis len.yo
Stopped in 50 steps at PC = 0x11.  Status 'HLT', CC Z=1 S=0 O=0
Changes to registers:
%eax:
 
0x00000000
 
0x00000004
%ecx:
 
0x00000000
 
0x00000004
%edx:
 
0x00000000
 
0x00000028
%esp:
 
0x00000000
 
0x00000100
%ebp:
 
0x00000000
 
0x00000100
 
Changes to memory:
0x00ec:
 
0x00000000
 
0x000000f8
0x00f0:
 
0x00000000
 
0x00000039
0x00f4:
 
0x00000000
 
0x00000014
0x00f8:
 
0x00000000
 
0x00000100
0x00fc:
 
0x00000000
 
0x00000011
 
M
I
P
S
 
R
e
g
i
s
t
e
r
s
 
M
I
P
S
 
I
n
s
t
r
u
c
t
i
o
n
 
E
x
a
m
p
l
e
s
 
L
o
a
d
/
S
t
o
r
e
 
addu $3,$2,$1
  
# Register add: $3 = $2+$1
 
addu $3,$2, 3145
 
# Immediate add: $3 = $2+3145
sll $3,$2,2
  
# Shift left: $3 = $2 << 2
 
lw $3,16($2)
  
# Load Word: $3 = M[$2+16]
sw $3,16($2)
  
# Store Word: M[$2+16] = $3
 
B
r
a
n
c
h
 
beq $3,$2,dest
 
# Branch when $3 = $2
 
C
I
S
C
 
v
s
.
 
R
I
S
C
 
O
r
i
g
i
n
a
l
 
D
e
b
a
t
e
S
t
r
o
n
g
 
o
p
i
n
i
o
n
s
!
C
I
S
C
 
p
r
o
p
o
n
e
n
t
s
-
-
-
e
a
s
y
 
f
o
r
 
c
o
m
p
i
l
e
r
,
 
f
e
w
e
r
 
c
o
d
e
 
b
y
t
e
s
R
I
S
C
 
p
r
o
p
o
n
e
n
t
s
-
-
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
n
o
u
g
h
 
h
a
r
d
w
a
r
e
,
 
c
a
n
 
m
a
k
e
 
a
l
m
o
s
t
 
a
n
y
t
h
i
n
g
 
g
o
 
f
a
s
t
I
n
t
e
l
 
h
a
s
 
e
v
o
l
v
e
d
 
f
r
o
m
 
I
A
3
2
 
t
o
 
x
8
6
-
6
4
U
s
e
s
 
6
4
-
b
i
t
 
w
o
r
d
s
 
(
i
n
c
l
u
d
i
n
g
 
a
d
d
r
e
s
s
e
s
)
A
d
o
p
t
e
d
 
s
o
m
e
 
f
e
a
t
u
r
e
s
 
f
o
u
n
d
 
i
n
 
R
I
S
C
»
More registers (16)
»
Less reliance on stack
Slide Note
Embed
Share

Y86 Instruction Set Architecture is a simplified pseudo-language based on x86 (IA-32) architecture. It involves implementing the Fetch-Decode-Execute cycle, where instructions are fetched from memory, decoded, and executed. The Y86 ISA offers a simpler set of instructions and formats compared to x86, making it suitable for educational purposes in learning hardware architecture design. The Y86 processor state includes program registers, condition codes, memory organization, and encoding registers for efficient data processing.

  • Y86 Instruction Set
  • Computer Architecture
  • Hardware Design
  • Fetch-Decode-Execute
  • Educational

Uploaded on Sep 21, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. CS:APP Chapter 4 Computer Architecture Processor Architecture Randal E. Bryant adapted by Jason Fritts then by David Ferry http://csapp.cs.cmu.edu CS:APP2e

  2. Rest of this course: Implementing the Fetch-Decode-Execute Cycle Fetch Fetch next instruction to be executed from memory Program counter (PC) holds the address of the next instruction to be executed Fetch Decode Execute Decode Decode instruction, and send control signals to parts of datapath Identify what instruction to execute Identify what registers to read/write Identify what immediates to use Read register values from register file Execute Perform specified operation on the data Save results in register or memory Update the PC CS:APP2e 2

  3. Hardware Architecture - using Y86 ISA For learning aspects of hardware architecture design, we ll be using the Y86 ISA x86 is a CISC language too complex for educational purposes Y86 Instruction Set Architecture a pseudo-language based on x86 (IA-32) similar state, but simpler set of instructions simpler instruction formats and addressing modes more RISC-like ISA than IA-32 Format 1 6 bytes of information read from memory can determine instruction length from first byte CS:APP2e 3

  4. Y86 Instruction Set and Formatting Byte 0 1 2 3 4 5 halt 0 0 nop 1 0 rrmovl rA, rB rA rB 2 0 irmovl V, rB rB V 3 0 F rmmovl rA, D(rB) rA rB D 4 0 mrmovl D(rB), rA rA rB D 5 0 OPl rA, rB fn rA rB 6 jXX Dest fn Dest 7 call Dest Dest 8 0 ret 9 0 pushl rA rA A 0 F popl rA rA B 0 F CS:APP2e 6

  5. Y86 Processor State RF: Program registers CC: Stat: Program status Condition codes %eax %ecx %edx %ebx %esi %edi %esp %ebp DMEM: Memory ZF SF OF PC Program Registers Same 8 as with IA32. Each 32 bits Condition Codes Single-bit flags set by arithmetic or logical instructions ZF: Zero SF:Negative Program Counter Indicates address of next instruction OF: Overflow Program Status Indicates either normal operation or some error condition Memory Byte-addressable storage array Words stored in little-endian byte order CS:APP2e 7

  6. Encoding Registers Each register has 4-bit ID %eax %ecx %edx %ebx 0 1 2 3 %esi %edi %esp %ebp 6 7 4 5 Same encoding as in IA32 Register ID 15 (0xF) indicates no register Will use this in our hardware design in multiple places CS:APP2e 8

  7. Instruction Example Addition Instruction Generic Form Encoded Representation addl rA, rB 0 rA rB 6 Add value in register rA to that in register rB Store result in register rB Note that Y86 only allows addition to be applied to register data Set condition codes based on result e.g., addl %ebx,%esi Encoding: 60 36 Two-byte encoding First indicates instruction type Second gives source and destination registers CS:APP2e 9

  8. Arithmetic and Logical Operations Instruction Code Function Code Refer to generically as OPl Encodings differ only by function code Low-order 4 bytes in first instruction word Add addl rA, rB 0 rA rB 6 Subtract (rA from rB) subl rA, rB 1 rA rB 6 Set condition codes as side effect And andl rA, rB 2 rA rB 6 Exclusive-Or xorl rA, rB 3 rA rB 6 CS:APP2e 10

  9. Y86 Instruction Set #2 Byte 0 1 2 3 4 5 halt 0 0 addl 6 0 nop 1 0 subl 6 1 rrmovl rA, rB rA rB 2 0 andl 6 2 irmovl V, rB rB V 3 0 F xorl 6 3 rmmovl rA, D(rB) rA rB D 4 0 mrmovl D(rB), rA rA rB D 5 0 OPl rA, rB fn rA rB 6 jXX Dest fn Dest 7 call Dest Dest 8 0 ret 9 0 pushl rA rA A 0 F popl rA rA B 0 F CS:APP2e 11

  10. Move Operations Register --> Register rrmovl rA, rB 0 rA rB 2 Immediate --> Register 3 0 F rB V irmovl V, rB Register --> Memory rmmovl rA, D(rB) 4 0 rA rB D Memory --> Register 5 0 rA rB D mrmovl D(rB), rA Like the IA32 movl instruction Simpler format for memory addresses Give different names to keep them distinct CS:APP2e 12

  11. Move Instruction Examples IA32 Y86 Encoding movl $0xabcd, %edx irmovl $0xabcd, %edx 30 f2 cd ab 00 00 movl %esp, %ebx rrmovl %esp, %ebx 20 43 mrmovl -12(%ebp),%ecx movl -12(%ebp),%ecx 50 15 f4 ff ff ff rmmovl %esi,0x41c(%esp) movl %esi,0x41c(%esp) 40 64 1c 04 00 00 movl $0xabcd, (%eax) movl %eax, 12(%eax,%edx) movl (%ebp,%eax,4),%ecx CS:APP2e 14

  12. Jump Instructions Jump Unconditionally Refer to generically as jXX Encodings differ only by function code Based on values of condition codes Same as IA32 counterparts Encode full destination address Unlike PC-relative addressing seen in IA32 jmp Dest 7 0 Dest Jump When Less or Equal jle Dest 7 1 Dest Jump When Less jl Dest 7 2 Dest Jump When Equal je Dest 7 3 Dest Jump When Not Equal jne Dest 7 4 Dest Jump When Greater or Equal jge Dest 7 5 Dest Jump When Greater jg Dest 7 6 Dest CS:APP2e 16

  13. Y86 Instruction Set #3 Byte 0 1 2 3 4 5 halt 0 0 nop 1 0 rrmovl rA, rB rA rB 2 0 irmovl V, rB rB V 3 0 F rmmovl rA, D(rB) rA rB D 4 0 jmp 7 0 mrmovl D(rB), rA rA rB D 5 0 jle 7 1 OPl rA, rB fn rA rB 6 jl 7 2 jXX Dest fn Dest 7 je 7 3 call Dest Dest 8 0 jne 7 4 ret 9 0 jge 7 5 pushl rA rA A 0 F jg 7 6 popl rA rA B 0 F CS:APP2e 17

  14. Stack Operations pushl rA 0 rA F A Decrement %esp by 4 Store word from rA to memory at %esp Like IA32 popl rA 0 rA F B Read word from memory at %esp Save in rA Increment %esp by 4 Like IA32 CS:APP2e 18

  15. Y86 Program Stack Stack Bottom Region of memory holding program data Used in Y86 (and IA32) for supporting procedure calls Stack top indicated by %esp Address of top stack element Increasing Addresses Stack grows toward lower addresses Top element is at highest address in the stack When pushing, must first decrement stack pointer After popping, increment stack pointer %esp Stack Top CS:APP2e 19

  16. Subroutine Call and Return call Dest 8 0 Dest Push address of next instruction onto stack Start executing instructions at Dest Like IA32 9 0 ret Pop value from stack Use as address for next instruction Like IA32 CS:APP2e 20

  17. Miscellaneous Instructions 1 0 nop Don t do anything 0 0 halt Stop executing instructions IA32 has comparable instruction, but can t execute it in user mode Encoding ensures that program hitting memory initialized to zero will halt CS:APP2e 21

  18. Status Conditions Mnemonic AOK Code 1 Normal operation Halt instruction encountered Mnemonic HLT Code 2 Bad address (either instruction or data) encountered Mnemonic ADR Code 3 Invalid instruction encountered Mnemonic INS Code 4 Desired Behavior If AOK, keep going Otherwise, stop program execution CS:APP2e 22

  19. Y86 Code vs X86 Code Coding Example Find number of elements in null-terminated list int len1(int a[]); a 5043 6125 7395 0 3 CS:APP2e 23

  20. Y86 Code Generation Example First Try Write typical array code Problem Hard to do array indexing on Y86 Since don t have scaled addressing modes /* Find number of elements in null-terminated list */ int len1(int a[]) { int len; for (len = 0; a[len]; len++) ; return len; } L5: incl %eax cmpl $0, (%edx,%eax,4) jne L5 CS:APP2e 24

  21. Y86 Code Generation Example #2 Second Try Write with pointer code Result Don t need to do indexed addressing /* Find number of elements in null-terminated list */ int len2(int a[]) { int len = 0; while (*a++) len++; return len; } .L11: incl movl addl testl jne .L11 %ecx (%edx), %eax $4, %edx %eax, %eax CS:APP2e 25

  22. Y86 Code Generation Example #3 IA32 Code Setup Y86 Code Setup len2: len2: pushl %ebp movl %esp, %ebp pushl %ebp rrmovl %esp, %ebp # New FP pushl %esi irmovl $4, %esi pushl %edi irmovl $1, %edi mrmovl 8(%ebp), %edx irmovl $0, %ecx mrmovl (%edx), %eax addl %esi, %edx andl %eax, %eax je Done # If zero, goto Done # Save %ebp # Save # Constant 4 # Save # Constant 1 # Get a # len = 0 # Get *a # a++ # Test *a movl 8(%ebp), %edx movl $0, %ecx movl (%edx), %eax addl $4, %edx testl %eax, %eax je .L13 Use andl to test register Need constants 1 & 4 Store in callee-save registers CS:APP2e 26

  23. Y86 Code Generation Example #4 IA32 Code Loop & Exit Y86 Code Loop & Exit .L11: incl %ecx movl (%edx), %eax addl $4, %edx testl %eax, %eax jne .L11 Loop: addl %edi, %ecx mrmovl (%edx), %eax addl %esi, %edx andl %eax, %eax jne Loop # If !0, goto Loop # len++ # Get *a # a++ # Test *a .L13: movl %ecx, %eax Done: rrmovl %ecx, %eax # return len popl %edi # Restore %edi popl %esi # Restore %esi rrmovl %ebp, %esp # Restore SP popl %ebp # Restore FP ret leave ret CS:APP2e 27

  24. Y86 Code Generation Example #5 IA32 Code Finish Y86 Code Finish .L13: movl %ecx, %eax Done: rrmovl %ecx, %eax # return len popl %edi # Restore %edi popl %esi # Restore %esi rrmovl %ebp, %esp # Restore SP popl %ebp # Restore FP ret leave ret CS:APP2e 28

  25. Summary Y86 Instruction Set Architecture Similar state and instructions as IA32 Simpler encodings Somewhere between CISC and RISC How Important is ISA Design? Less now than before With enough hardware, can make almost anything go fast Intel has evolved from IA32 to x86-64 Uses 64-bit words (including addresses) Adopted some features found in RISC More registers (16) Less reliance on stack CS:APP2e 37

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#