top decor
Step by Step Example Program to realize


Problem specification

Two integer numbers: A and B are stored in memory cells with addresses 30 and 38. Our program must compare these values and print to screen the results. For example, if A=3 and B=6 the output must be

compare result: A<B

The solution

Our program extracts A to register $1, B to $2 and then compares them. MMIX instruction CMP has a remarkable feature to return serial values -1, 0 and 1 when the result is <0, =0 and >0 respectively. So we just have to add constant 3D to this result in order to get the code of required symbol of inequality: '<', '=' or '>'.

To print the results of our program to console we'll use a special system input/output TRAP with 05 first parameter. The second operand of such instruction in E-MMI defines the number of input/output function. In discussing problem I used two kinds of output functions: 02 - print symbol to console and 09 - print string to console. The last parameter of TRAP 5 instruction is a register number that specify symbol or string address.

Described above organization of output is the specific feature of E-MMI project.

address code mnemonics operation comments
0E3 00 0040SETL   $00, 0040$0 <== 40set $0 equal to address of the text
400 0509 00TRAP   5/09, $00print stringcall system function: print string
8E3 00 0030SETL   $00, 0030$0 <== 30set $0 equal to A addres
C8D 01 00 00LDOI   $01, $00 00$1 <== ($0)get 8-byte integer A value to $1
108D 02 00 08LDOI   $02, $00 08$2 <== ($0+8)get 8-byte integer B value to $2
1430 00 01 02CMP   $00, $01 $02$0 <== $1 cmp $2$0 = -1 if $1<$2, 0 if A=B, 1 if $1>$2
1821 00 00 3DADDI   $00, $00 3D$0 <== $0 + 3D ('=')$0 = '<' if $1<$2, '=' if A=B, '>' if $1>$2
1C00 0502 00TRAP   5/09, $00print symbolcall system function: print symbol
20E3 00 0042SETL   $00, 0042$0 <== 42 ('B')put code of symbol 'B' to $0
2400 0502 00TRAP   5/09, $00print symbolcall system function: print symbol
2800 000000TRAP   0exit to system 
2C(not used)
30 A
38 B
40
48
50
63 6F 6D 70 61 72 65 20
72 65 73 75 6C 74 3A 20
41 24
compare  
result:  
A$
text: 'compare result: A' and ending '$'

back previous page next page forward


Related topics:

E-MMI software
 

  (C) 2002, Evgeny Eremin. rEd-MMI project documentation
1