Dear professor Diehr
seems that your assembly code and algorithm are absoluelly correct and works perfectly.
The problem was with the assembly code I added. The ENTRY code section was missing some instructions. Instead of dealing with the argument values your code was being supplied with their addresses - I miss to de-reference them!
00029 * DE-REFERENCE ARGS 1 AND 2
00030 *
000E 01 C4800036 00031 LD I ADD1 ACC )-- ADDR OF 1ST ARG
0010 0 D025 00032 STO ADD1 ADD1 )-- 1ST ARG
0011 01 C4800037 00033 LD I ADD2 ACC )-- ADDR OF 2ND ARG
0013 0 D023 00034 STO ADD2 ADD2 )-- 2ND ARG
00035 *
So, now the tests produce the expected results. Congratulations professor - this is a really historic piece of computer programming art!
I added a 3rd argument to LGADD() function. Now it looks like this:
LGADD( n1, n2, OVRFL )
where OVRFL argument returns a boolean value (1=TRUE) indicating whether the sum operation resulted in overflow or not
Follows the code and job listing.
+ [[ CPU RUNNING ]]
PAGE 1
// JOB 1234
LOG DRIVE CART SPEC CART AVAIL PHY DRIVE
0000 1234 1234 0000
V2 M12 ACTUAL 16K CONFIG 16K
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PAGE 1 LOGADDER
// JOB LOGADDER
LOG DRIVE CART SPEC CART AVAIL PHY DRIVE
0000 1234 1234 0000
V2 M12 ACTUAL 16K CONFIG 16K
// ** LOGICAL ADDER FUNCTION
// ASM
*LIST
*PRINT SYMBOL TABLE
00001 ***************************************************
00002 * THIS ROUTINE WILL ADD TWO INTEGERS *
00003 * TOGETHER, AND TURN ON THE OVERFLOW *
00004 * INDICATOR IF ARITHMETIC OVERFLOW OCCURS *
00005 * WITHOUT USING ANY ARITHMETIC INSTRUCTIONS *
00006 ***************************************************
00007 * USING IBM-1130 CPU LOGICAL INSTRUCTIONS ONLY *
00008 ***************************************************
00009 * DIEHR, PETER SYSTEMS PROGRAMMER *
00010 * EMU INSTRUCTIONAL COMPUTER SERVICE, 1971 *
00011 ***************************************************
00012 * VINCENZI, CLAUDIO SYSTEMS PROGRAMMER *
00013 * CENTRO DE PROCESSAMENTO DE DADOS EESC USP, 1978 *
00014 ***************************************************
0000 131C1104 00015 ENT LGADD FUNCTION ENTRY POINT
0000 0 0000 00016 LGADD DC *-* RETURN ADDRESS
00017 *
0001 01 C4800000 00018 LD I LGADD ACC)-- LGDDR (LGADD POINTS
0003 0 D032 00019 STO ADD1 SAVE 1ST ARG ADDR
0004 01 74010000 00020 MDX L LGADD,1 INCREMENT LGADD
00021 *
0006 01 C4800000 00022 LD I LGADD ACC)-- LGDDR (LGADD POINTS TO ADD
0008 0 D02E 00023 STO ADD2 SAVE 2ND ARG ADDR
0009 01 74010000 00024 MDX L LGADD,1 INCREMENT LGADD
00025 *
000B 01 C4800000 00026 LD I LGADD ACC)-- LGDDR (LGADD POINTS TO ADD
000D 0 D02D 00027 STO OVRFL SAVE 3ND ARG ADDR (OVERFLOW FL
00028 *
00029 * DE-REFERENCE ARGS 1 AND 2
00030 *
000E 01 C4800036 00031 LD I ADD1 ACC )-- ADDR OF 1ST ARG
0010 0 D025 00032 STO ADD1 ADD1 )-- 1ST ARG
0011 01 C4800037 00033 LD I ADD2 ACC )-- ADDR OF 2ND ARG
0013 0 D023 00034 STO ADD2 ADD2 )-- 2ND ARG
00035 *
00036 * DO THE MATH...
00037 *
0014 0 C021 00038 LD ADD1 GET 1ST ADDEND AND SAVE
0015 0 D022 00039 STO SIGN *IT (FOR LATER ANALYSIS)
0016 0 F020 00040 EOR ADD2 EXCLUSIVE OR WITH 2ND ADDEND
0017 0 D021 00041 STO STATS *RESULT IS NEGATIVE ONLY IFF
00042 * THEY ARE OF OPPOSITE SIGN
0018 0 C01D 00043 LOOP LD ADD1 FETCH 1ST ADDEND
0019 0 E81D 00044 OR ADD2 'OR' WITH 2ND ADDEND
001A 0 D01F 00045 STO SUM *AND SAVE PARTIAL SUM
001B 0 C01A 00046 LD ADD1 FETCH 1ST ADDEND
001C 0 E01A 00047 AND ADD2 *'AND' WITH 2ND ADDEND
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PAGE 2 LOGADDER
001D 0 1001 00048 SLA 1 *AND MULTIPLY BY BASE (=2)
001E 0 D017 00049 STO ADD1 THIS REPRESENTS THE 'CARRIES'
001F 0 1801 00050 SRA 1 RESTORE TEMPORARILY
0020 0 F019 00051 EOR SUM *AND CHANGE PARTIAL SUMS
0021 0 D015 00052 STO ADD2 *TO REFLECT CARRIES PENDING
0022 0 C013 00053 LD ADD1 CHECK FOR CARRIES PENDING
0023 0 4820 00054 SKP Z SKIP OUT IF NONE (=0)
0024 0 70F3 00055 B LOOP *ELSE CONTINUES PROCESS
0025 0 C013 00056 LD STATS ADD COMPLETE - SIGN ANALYSIS
0026 0 4828 00057 SKP Z+ DON'T SKIP IF ORIGINALS HAD
0027 0 7008 00058 B DONE OPPOSITE SIGNS-IF SO, COMPLET
0028 0 C00F 00059 LD SIGN OTHERWISE FETCH REPRESENTATIO
0029 0 F00D 00060 EOR ADD2 *SIGN AND TEST IF RESULT
002A 0 4810 00061 SKP - *HAS THE SAME SIGN
002B 0 7004 00062 B DONE OK IF SAME SIGN
002C 0 2001 00063 LDS 1 *ELSE TURN ON OVERFLOW
002D 0 C00E 00064 LD ONE
002E 01 D480003B 00065 STO I OVRFL SET 3D ARG TO 1 IF OVERFLOW
00066 *
0030 00067 DONE EQU *
00068 *
0030 0 C009 00069 LD SUM RETURN VALUE (SUM)
00070 *
0031 01 74010000 00071 MDX L LGADD,1 INCREMENT MADDR TO CORRECT RET
0033 0 1000 00072 NOP
0034 01 4C800000 00073 BSC I LGADD RETURN TO CALLER
00074 *
0036 0 0000 00075 ADD1 DC 0
0037 0 0000 00076 ADD2 DC 0
0038 0 0000 00077 SIGN DC 0
0039 0 0000 00078 STATS DC 0
003A 0 0000 00079 SUM DC 0
003B 0 0000 00080 OVRFL DC 0
003C 0 0001 00081 ONE DC 1
003E 00082 END LGADD RETURN TO CALLER
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PAGE 3 LOGADDER *SYMBOL TABLE*
ADD1 0036 ADD2 0037 DONE 0030 LGADD 0000 LOOP 0018
ONE 003C OVRFL 003B SIGN 0038 STATS 0039 SUM 003A
000 OVERFLOW SECTORS SPECIFIED
000 OVERFLOW SECTORS REQUIRED
NO ERROR(S) AND NO WARNING(S) FLAGGED IN ABOVE ASSEMBLY
// DUP
*DELETE UA LGADD
CART ID 1234 DB ADDR 2793 DB CNT 0005
*STORE WS UA LGADD
CART ID 1234 DB ADDR 2795 DB CNT 0005
CART ID 1234 DB ADDR 2793 DB CNT 0002
*STORE WS UA ARADD
CART ID 1234 DB ADDR 2798 DB CNT 0002
// FOR
*LIST ALL
*ONE WORD INTEGERS
*IOCS(1132PRINTER)
** TEST OF ADD FUNCTIONS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PAGE 5 LOGADDER TEST OF ADD FUNCTIONS
C ****************************************************
C * THIS PROGRAM WILL TEST TWO ADD INTEGER FUNCTIONS *
C ****************************************************
C * USING IBM-1130 BASIC FORTRAN *
C ****************************************************
C * DIEHR, PETER SYSTEMS PROGRAMMER *
C * EMU INSTRUCTIONAL COMPUTER SERVICE, 1971 *
C ****************************************************
C * VINCENZI, CLAUDIO SYSTEMS PROGRAMMER *
C * CENTRO DE PROCESSAMENTO DE DADOS EESC USP, 1978 *
C ****************************************************
INTEGER N1, N2, SUM, OVRFL
INTEGER ARADD,LGADD
C
WRITE(3,300)
300 FORMAT(' TEST OF THE ARITHMETIC ADD ARADD() FUNCTION'/)
C
N1=0
N2=0
SUM=ARADD(N1,N2)
C
WRITE(3,310) N1,N2,SUM
C
N1=0
N2=1
SUM=ARADD(N1,N2)
C
WRITE(3,310) N1,N2,SUM
C
N1=1
N2=0
SUM=ARADD(N1,N2)
C
WRITE(3,310) N1,N2,SUM
C
N1=1
N2=1
SUM=ARADD(N1,N2)
C
WRITE(3,310) N1,N2,SUM
C
N1=67
N2=33
SUM=ARADD(N1,N2)
C
WRITE(3,310) N1,N2,SUM
C
310 FORMAT(' SUM OF N1=',I5,' AND N2=',I5,
* ' LGADD() RETURNS ',I6)
C
WRITE(3,330)
330 FORMAT(' TEST OF THE LOGICAL ADD LGADD() FUNCTION'/)
C
N1=0
N2=0
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PAGE 6 LOGADDER TEST OF ADD FUNCTIONS
C
N1=0
N2=1
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=1
N2=0
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=1
N2=1
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=67
N2=33
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=1023
N2=511
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=10240
N2=8192
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=16384
N2=16383
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
N1=16384
N2=16384
OVRFL=0
SUM=LGADD(N1,N2,OVRFL)
C
WRITE(3,320) N1,N2,SUM,OVRFL
C
320 FORMAT(' SUM OF N1=',I5,' AND N2=',I5,
* ' LGADD() RETURNS ',I6,' OVRFL=',I4)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
PAGE 7 LOGADDER TEST OF ADD FUNCTIONS
C
WRITE(3,390)
390 FORMAT(' CALL EXIT...')
CALL EXIT
END
VARIABLE ALLOCATIONS
N1(I )=0000 N2(I )=0001 SUM(I )=0002 OVRFL(I )=0003
STATEMENT ALLOCATIONS
300 =000F 310 =0028 330 =0042 320 =005A 390 =007A
FEATURES SUPPORTED
ONE WORD INTEGERS
IOCS
CALLED SUBPROGRAMS
ARADD LGADD FLD FSTO PRNTZ SWRT SCOMP SFIO SIOI
INTEGER CONSTANTS
3=0004 0=0005 1=0006 67=0007 33=0008 1023=0009 511=000A 10240=000B 8192=000C 16384=000D
16383=000E
CORE REQUIREMENTS FOR
COMMON 0 VARIABLES 4 PROGRAM 562
END OF COMPILATION
// XEQ
TEST OF THE ARITHMETIC ADD ARADD() FUNCTION
SUM OF N1= 0 AND N2= 0 LGADD() RETURNS 0
SUM OF N1= 0 AND N2= 1 LGADD() RETURNS 1
SUM OF N1= 1 AND N2= 0 LGADD() RETURNS 1
SUM OF N1= 1 AND N2= 1 LGADD() RETURNS 2
SUM OF N1= 67 AND N2= 33 LGADD() RETURNS 100
TEST OF THE LOGICAL ADD LGADD() FUNCTION
SUM OF N1= 0 AND N2= 0 LGADD() RETURNS 0 OVRFL= 0
SUM OF N1= 0 AND N2= 1 LGADD() RETURNS 1 OVRFL= 0
SUM OF N1= 1 AND N2= 0 LGADD() RETURNS 1 OVRFL= 0
SUM OF N1= 1 AND N2= 1 LGADD() RETURNS 2 OVRFL= 0
SUM OF N1= 67 AND N2= 33 LGADD() RETURNS 100 OVRFL= 0
SUM OF N1= 1023 AND N2= 511 LGADD() RETURNS 1534 OVRFL= 0
SUM OF N1=10240 AND N2= 8192 LGADD() RETURNS 18432 OVRFL= 0
SUM OF N1=16384 AND N2=16383 LGADD() RETURNS 32767 OVRFL= 0
SUM OF N1=16384 AND N2=16384 LGADD() RETURNS -32768 OVRFL= 1
+ [[ CPU STOPPING ]]
$
$ Stop due 'CPU WAIT', (stop code=01), CPU Wait for Program Start
$ -------- '--------', (------------), --------------------------
$ Stopped with: IAR: 0x002A SAR: 0x0029 SBR: 0x3000
$ Stopped at: IAR: 0x0029 (0x0000 0x00 0x00 S +0x00 ( +0))
$ Followed by: IAR: 0x002A (0x4C80 0x09 BSC I 0x0028 +0x00 ( +0))
$ Elapsed Time: 18s
$ ACC Code: 0x1000, intervention required on 1442 Card RP/P
$ ---------------------------------------------------------------
[Mon Oct 28 21:05:24 2024] sim>
Claudio:
I seem to need simpler test cases, for example:
N1=1
N2=0
WRITE(3,320) N1,NE,LGADD(N1,N2)
N1=0
N2=1
WRITE(3,320) N1,NE,LGADD(N1,N2)
N1=7
N2=8
WRITE(3,320) N1,NE,LGADD(N1,N2)
N1=1
N2=1
WRITE(3,320) N1,NE,LGADD(N1,N2)
N1=3
N2=1
WRITE(3,320) N1,NE,LGADD(N1,N2)
N1=1
N2=3
WRITE(3,320) N1,NE,LGADD(N1,N2)
This will provide several easy to follow cases, with planned carries.
In the old days, I would have done one of three things:
1. looked hard enough to find the error - but this isn't working for me today!
2. Run this segment in single step mode, checking what is being done - not available to me today.
3. Run my handy single step mode debugger program, which would print an execution trace, along with data dumps of altered registers and data items. But the code for this is long gone ...
So if you can run these test cases for me, Claudio, I can maybe make some progress.
Two questions on the IBM 1130 emulator: does it carry out every instruction exactly the way the IBM 1130 did? This code has some assumptions:
1. Logical operators, OR, AND, XOR work simultaneously on all 16 bits of the word. Programs like Excel do NOT, hence I cannot replicate the logic with an Excel spreadsheet, which I tried yesterday.
I'm hoping to get past this with these test cases.
Thanks, Claudio!
Best regards, Peter Diehr
-- Claudio Vincenzi