-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine_types.h
executable file
·94 lines (69 loc) · 3.24 KB
/
machine_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// $Id: machine_types.h,v 1.29 2024/08/29 21:58:39 leavens Exp $
// Machine Types for the Simplified Stack Machine (SSM)
#ifndef _MACHINE_TYPES_H
#define _MACHINE_TYPES_H
#define BYTES_PER_WORD 4
// operation codes
typedef unsigned short opcode_type;
// registers encoded in instructions
typedef unsigned short reg_num_type;
// offset values (which are signed) encoded in instructions
typedef short offset_type;
// function codes in computational instructions
typedef unsigned short func_type;
// argument values (signed) encoded in instructions
typedef short arg_type;
// shift values encoded in other computational instructions
typedef unsigned short shift_type;
// immediate operands encoded in instructions
typedef int immediate_type;
// unsigned immediate operands in instructions
typedef unsigned int uimmed_type;
// addresses, assuming ints are 32 bits
typedef unsigned int address_type;
// machine words, assuming ints are 32 bits
typedef int word_type;
// machine words, unsigned
typedef unsigned int uword_type;
// bytes, assuming chars are 8 bits
typedef unsigned char byte_type;
#define NINEBITSMAXSIGNED 0xff
#define NINEBITSMINSIGNED -512
#define TWELVEBITSMAXSIGNED 0x7ff
#define TWELVEBITSMINSIGNED -0x800
#define TWELVEBITSMAXUNSIGNED 0xfff
#define SIXTEENBITSMAXSIGNED 0777
#define SIXTEENBITSMINSIGNED -01000
#define SIXTEENBITSMAXUNSIGNED 0xffff
#define TWENTYEIGHTBITSMAXUNSIGNED 0xfffffff
// Return the sign-extended equivalent of i
extern word_type machine_types_sgnExt(immediate_type i);
// Return the zero-extended equivalent of i
extern uword_type machine_types_zeroExt(immediate_type i);
// Return the offset given by o,
// which is the sign extension of o
extern word_type machine_types_formOffset(immediate_type o);
// Return an address formed by concatenating the instruction address, a,
// with the high-order (4) bits of the PC.
extern address_type machine_types_formAddress(address_type PC, address_type a);
// Check that o can be represented as an offset field in an instruction
// bail with an error message if not (so doesn't return if wrong)
extern void machine_types_check_fits_in_offset(word_type o);
// Check that arg can be represented as an arg field in an instruction,
// bail with an error message if not (so doesn't return if wrong)
extern void machine_types_check_fits_in_arg(word_type arg);
// Check that arg can be represented as a shift field in an instruction,
// bail with an error message if not (so doesn't return if wrong)
extern void machine_types_check_fits_in_shift(word_type arg);
// Check that immed can be represented as a signed immediate field,
// bail with an error message if not (so doesn't return if wrong)
extern void machine_types_check_fits_in_immed(word_type immed);
// Check that arg can be represented as unsigned immediate field,
// bail with an error message if not (so doesn't return if wrong)
extern void machine_types_check_fits_in_uimmed(word_type arg);
// Check that addr can be represented as an address field in an instruction,
// bail with an error message if not (so doesn't return if wrong)
extern void machine_types_check_fits_in_addr(address_type addr);
// the following line is for the documentation
// ...
#endif