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_ROR.py,v 1.1 2002/02/23 01:35:39 troth Exp $
26
"""Test the ROR opcode.
30
from registers import Reg, SREG
32
class ROR_TestFail(base_test.TestFail): pass
34
class base_ROR(base_test.opcode_test):
35
"""Generic test case for testing ROR opcode.
37
ROR - Rotate Right through Carry
38
opcode is '1001 010d dddd 0111' where d is register (0-31)
40
Only registers PC, Rd and SREG should be changed.
44
self.setup_regs[Reg.SREG] = (self.C << SREG.C)
46
# Set the register values
47
self.setup_regs[self.Rd] = self.Vd
49
# Return the raw opcode
50
return 0x9407 | (self.Rd << 4)
52
def analyze_results(self):
53
self.reg_changed.extend( [self.Rd, Reg.SREG] )
55
# check that result is correct
56
expect = ( ((self.Vd >> 1) & 0x7f) | (self.C << 7))
58
got = self.anal_regs[self.Rd]
61
self.fail('ROR r%02d: 0x%02x = (expect=%02x, got=%02x)' % (
62
self.Rd, self.Vd, expect, got))
66
# calculate what we expect sreg to be (I, T and H should be zero)
68
N = ((expect & 0x80) != 0)
70
expect_sreg += (N ^ V) << SREG.S
71
expect_sreg += V << SREG.V
72
expect_sreg += N << SREG.N
73
expect_sreg += (expect == 0) << SREG.Z
74
expect_sreg += C << SREG.C
76
got_sreg = self.anal_regs[Reg.SREG]
78
if expect_sreg != got_sreg:
79
self.fail('ROR r%02d: 0x%02x -> SREG (expect=%02x, got=%02x)' % (
80
self.Rd, self.Vd, expect_sreg, got_sreg))
83
# Template code for test case.
84
# The fail method will raise a test specific exception.
87
class ROR_r%02d_v%02x_C%d_TestFail(ROR_TestFail): pass
89
class test_ROR_r%02d_v%02x_C%d(base_ROR):
94
raise ROR_r%02d_v%02x_C%d_TestFail, s
98
# Define a list of test values such that we test all the cases of SREG bits being set.
111
# automagically generate the test_ROR_rNN_vXX_rrNN_kXX class definitions.
118
code += template % args