Code covered by the BSD License  

Highlights from
Extended Brookshear Machine emulator and assembler

image thumbnail
from Extended Brookshear Machine emulator and assembler by David Young
Emulator and assembler for a simple computer, a teaching aid for computer science courses.

regstrings(machine)
function c = regstrings(machine)
%REGSTRINGS returns strings representing the current state of the registers
%   C = REGSTRINGS(MACHINE) produces a cell array of strings representing
%   the current state of the registers of the BM MACHINE.
%
%   If called with no argument, returns header strings.
%
%   If MACHINE is the empty matrix, returns results for a machine that has
%   been cleared.
%
%   See also: BITS2STRINGS

%   Copyright 2008 University of Sussex and David Young

if nargin == 0
    c = bits2strings;
    c{1} = 'Register';
    return
end

if isempty(machine)
    machine = newbm;
end
m = machine.register;

c = cell(length(m), length(bits2strings));
for i = 1:length(m);
    c(i, :) = bits2strings(i-1, m(i), 'reg');
end

end

Contact us at files@mathworks.com