Bräuchte bei prog eure hilfe. Muss ein CPU simultator programmieren weiss nicht wie ich das angehen soll! hoffe ihr könnt mir da weiterhelfen!!
wir haben eine text datei vorgegeben und dazu muss ich ein prog.schreiben das diese punkte erfüllt:
2)replace all constants with their values and remove the definition lines containing the constants,
3)map the commands to address locations evaluating and replacing the .org commands (the entire address range is linear covering 2^9 address locations),
4)replace the labels within the code with addresses and replace the variable names with their locations that were assigned in the previous step.
5)Finally write the initial values of the variables to the according locations.
Quellcode
- ; a simple program that adds two constants using a sub-routine and stores
- ; the result in a variable vc
- ;
- ca .equ 5 ; define a constant ca with value 5
- cb .equ 7 ; define a constant cb with value 7
- .org 128
- vc .dw 0 ; define a variable vc at address 128 (= 0x80) with value 0
- .org 0
- _main:
- lda,c ca ; load constant ca to accu
- push,r a ; push accu to the stack
- lda,c cb ; load constant cb to accu
- push,r a ; push accu to the stack
- call sum ; call sub-routine sum
- sta vc ; vc = accu
- inc,r sp,2 ; deallocate parameter stack
- jmp _end ; jmp to label end
- _sum:
- push,r fp ; save old framepointer
- ldr fp,sp ; mark current frame
- dec,r sp,1 ; space for temp below the fp
- lda,c 0 ; accu = 0
- sta,ri fp,-1 ; temp = accu
- lda,ri fp,2 ; accu = 7 (via stack)
- add,ri fp,3 ; accu = 7 + 5 (via stack)
- sta,ri fp,-1 ; temp = accu
- lda,ri fp,-1 ; accu = temp
- ldr sp,fp ; remove locals from stack
- pop,r fp ; restore fp of caller
- ret ; back to caller
- _end:
- .end
- so soll die neue datei dann ausschauen:
- 0x000:
- 0x002:
- 0x004:
- 0x006:
- 0x008:
- 0x010:
- 0x012:
- 0x014:
- 0x016:
- 0x018:
- 0x020:
- 0x022:
- 0x024:
- 0x026:
- 0x028:
- 0x030:
- 0x032:
- 0x034:
- 0x036:
- 0x038:
- 0x040:
- ...
- 0x080:
- lda,c 5
- push,r a
- lda,c 7
- push,r a
- call 0x016
- sta 0x080
- inc,r sp,2
- jmp 0x040
- push,r fp
- ldr fp,sp
- dec,r sp,1
- lda,c 0
- sta,ri fp,-1
- lda,ri fp,2
- add,ri fp,3
- sta,ri fp,-1
- lda,ri fp,-1
- ldr sp,fp
- pop,r fp
- ret
- .end
- ...
- 0
Mfg
Kebapmaster
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Broken Sword () aus folgendem Grund: code-Tag hinzugefügt