-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
. | ||
. Modified from figure 2.1 in the textbook | ||
. input device : DEV04 | ||
. output device: DEV05 | ||
. | ||
COPY START 1000 | ||
FIRST STL RETADR | ||
CLOOP JSUB RDREC | ||
LDA LENGTH | ||
COMP ZERO | ||
JEQ ENDFIL | ||
JSUB WRREC | ||
J CLOOP | ||
ENDFIL LDA EOF | ||
STA BUFFER | ||
LDA THREE | ||
STA LENGTH | ||
JSUB WRREC | ||
LDL RETADR | ||
RSUB | ||
EOF BYTE C'EOF' | ||
THREE WORD 3 | ||
ZERO WORD 0 | ||
RETADR RESW 1 | ||
LENGTH RESW 1 | ||
BUFFER RESB 4096 | ||
. | ||
. SUBROUTINE TO READ RECORD INTO BUFFER | ||
. | ||
RDREC LDX ZERO | ||
LDA ZERO | ||
RLOOP TD INPUT | ||
JEQ RLOOP | ||
RD INPUT | ||
COMP ZERO | ||
JEQ EXIT | ||
STCH BUFFER | ||
TIX MAXLEN | ||
JLT RLOOP | ||
EXIT STX LENGTH | ||
RSUB | ||
INPUT BYTE X'04' | ||
MAXLEN WORD 4096 | ||
. | ||
. SUBROUTINE TO WRITE RECORD FROM BUFFER | ||
. | ||
WRREC LDX ZERO | ||
WLOOP TD OUTPUT | ||
JEQ WLOOP | ||
LDCH BUFFER | ||
WD OUTPUT | ||
TIX LENGTH | ||
JLT WLOOP | ||
RSUB | ||
OUTPUT BYTE X'05' | ||
END FIRST |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
file = open('fig2_1.asm') | ||
instructions, symbols, symbol_table = [],{},{} | ||
for line in file.readlines(): | ||
if line[0]!='.': | ||
line = line.replace('\n','').split(' ') | ||
instructions.append(list(filter(lambda x : x!='', line))) | ||
if len(instructions[-1]) == 3: symbols[instructions[-1][0]] = False | ||
variable = {'WORD':3,'BYTE':1} | ||
buffer = {'RESB':1,'RESW':3} | ||
for instruction in instructions: | ||
if len(instruction) == 1:continue | ||
elif len(instruction) == 2: | ||
if symbols[instruction[1]]:continue | ||
else:symbol_table[instruction[1]] = [instruction[1],None,None] | ||
else: | ||
if symbols[instruction[0]]:continue | ||
else: | ||
if instruction[1] in variable.keys(): symbol_table[instruction[0]] = [instruction[0],variable[instruction[1]],instruction[2]] | ||
elif instruction[1] in buffer.keys(): symbol_table[instruction[0]] = [instruction[0],buffer[instruction[1]]*int(instruction[2]),'--'] | ||
else: symbol_table[instruction[0]] = [instruction[0],3,'--'] | ||
symbols[instruction[0]] = True | ||
if instruction[2] in symbols.keys() and symbols[instruction[2]]==False: symbol_table[instruction[2]] = [instruction[2],None,None] | ||
for symbol in symbol_table.values(): | ||
print("{0}".format(symbol[0]).ljust(10),"{0}".format(symbol[1]).ljust(5),"{0}".format(symbol[2]).ljust(5)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
infix = input("Enter infix expression : ").replace(' ','') | ||
result = input("Enter resultant variable : ") | ||
temp,string,operators = {},[],['+','-','*','/'] | ||
count,cp = 1,0 | ||
|
||
for i in range(len(infix)): | ||
if infix[i] in operators: | ||
string.append(infix[cp:i]) | ||
string.append(infix[i]) | ||
cp = i+1 | ||
|
||
string.append(infix[cp:]) | ||
|
||
for i in range(len(string)): | ||
if '[' in string[i]: | ||
|
||
temp['t'+str(count)] = ('*',string[i][string[i].index('[')+1],'8') | ||
count += 1 | ||
temp['t'+str(count)] = ('[]',string[i][:string[i].index('[')],'t'+str(count-1)) | ||
string[i] = 't'+str(count) | ||
count += 1 | ||
|
||
|
||
while len(string)!=1: | ||
|
||
temp['t'+str(count)] = (string[1],string[0],string[2]) | ||
string = string[3:] | ||
string = ['t'+str(count)] + string | ||
count += 1 | ||
|
||
print('\n','THREE ADDRESS CODES'.center(15,' ')) | ||
for k,v in temp.items(): | ||
if v[0]!='[]': | ||
print(k.center(3,' '),'='.center(3,' '),v[1].center(3,' '),v[0].center(3,' '),v[2]) | ||
else : | ||
print(k.center(3,' '),'='.center(3,' '),v[1].center(3,' '),'['+v[2]+']') | ||
print(result.center(3,' '), '='.center(3,' '), 't{0}'.format(count-1).center(3,' ')) | ||
|
||
temp[result] = ('=','t'+str(count-1),'---') | ||
print("\n","QUADRUPLE TABLE".center(20,' ')) | ||
print('op'.center(3,' '),'arg1'.center(5,' '),'arg2'.center(5,' '),'result'.center(7,' ')) | ||
for k,v in temp.items(): print(v[0].center(3,' '),v[1].center(5,' '),v[2].center(5,' '),k.center(7,' ')) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
postfix = input("Enter postfix expression : ").replace(' ','') | ||
result = input("Enter resultant variable : ") | ||
temp,string,stack,operators = {},[],[_ for _ in postfix],['+','-','*','/'] | ||
count = 1 | ||
while len(stack)!=0: | ||
if stack[0] in operators: | ||
temp['t'+str(count)] = (stack[0],string[0],string[1]) | ||
stack[0] = 't'+str(count) | ||
string = [] | ||
count += 1 | ||
else: | ||
string.append(stack[0]) | ||
stack = stack[1:] | ||
|
||
print('\n','THREE ADDRESS CODES'.center(15,' ')) | ||
for k,v in temp.items(): print(k.center(3,' '),'='.center(3,' '),v[1].center(3,' '),v[0].center(3,' '),v[2].center(3,' ')) | ||
print(result.center(3,' '), '='.center(3,' '), 't{0}'.format(count-1).center(3,' ')) | ||
|
||
|
||
temp[result] = ('=','t'+str(count-1),'---') | ||
print("\n","QUADRUPLE TABLE".center(20,' ')) | ||
print('op'.center(3,' '),'arg1'.center(5,' '),'arg2'.center(5,' '),'result'.center(7,' ')) | ||
for k,v in temp.items(): print(v[0].center(3,' '),v[1].center(5,' '),v[2].center(5,' '),k.center(7,' ')) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.