2
###############################################################################
4
# simulavr - A simulator for the Atmel AVR family of microcontrollers.
5
# Copyright (C) 2001, 2002 Theodore A. Roth
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
###############################################################################
23
# $Id: test_ST_X.py,v 1.1 2002/04/04 22:16:54 troth Exp $
26
"""Test the ST_X opcode.
30
from registers import Reg, SREG
32
class ST_X_TestFail(base_test.TestFail): pass
34
class base_ST_X(base_test.opcode_test):
35
"""Generic test case for testing ST_X opcode.
37
ST_X - Store Indirect to data space from Register using index X
41
opcode is '1001 001d dddd 1100' where 0 <= d <= 31
43
Only registers PC should be changed.
46
# Set the register values
47
self.setup_regs[self.Rd] = self.Vd
48
self.setup_regs[Reg.R26] = (self.X & 0xff)
49
self.setup_regs[Reg.R27] = (self.X >> 8)
51
# Return the raw opcode
52
return 0x920C | (self.Rd << 4)
54
def analyze_results(self):
55
# check that result is correct
57
# FIXME: [TRoth 2002/04/04] Is this really what we should expect?
58
if self.Rd == Reg.R26:
59
expect = self.setup_regs[Reg.R26]
60
elif self.Rd == Reg.R27:
61
expect = self.setup_regs[Reg.R27]
65
got = self.mem_byte_read( self.X )
68
self.fail('ST_X: expect=%02x, got=%02x' % (expect, got))
71
# Template code for test case.
72
# The fail method will raise a test specific exception.
75
class ST_X_r%02d_X%04x_v%02x_TestFail(ST_X_TestFail): pass
77
class test_ST_X_r%02d_X%04x_v%02x(base_ST_X):
82
raise ST_X_r%02d_X%04x_v%02x_TestFail, s
86
# automagically generate the test_ST_X_* class definitions.
90
for x in (0x10f, 0x1ff):
91
for v in (0xaa, 0x55):
93
code += template % args