Hello. I have been assigned a programming task which is to be completed using assembly language for motorolla 68k (os9). I will attach the assignment brief to the email and a copy of the source code in a txt file. I have to adapt the code so that it does the following things:

1. Ask for and read in an array of characters,

2. Reverse the order of the characters in the array by means of a loop that pushing them on your user stack and then pops them back to the array

3. Print out with a suitable header the reversed order array.

4. Push three word values defined by you from memory onto your user stack

5. Use a subroutine to add together the words and return the answer to the stack

6. Force the calling programme to retrieve the answer and place it in a memory location.

7. Print this answer as a string to the screen.

All IO must be neatly formatted and use suitable dialogue and headings.

any help and/or insights you can offer will be very much appreciated. Thank you.

8 Years
Discussion Span
Last Post by OzY360

i shud add that il b very annoyed if sum 1 just posts the solution up so that i get an easy A. I dont care about gettin an A i want to learn Assembly!! In particular for this excercise i would like to understand arrays in more depth as i am confused about this particular concept. Please remember that i need help with assembly language specific to Motorolla 68k. I've been sittin here all day thinking about the problem but i'm stumped so i've tried looking at many other resources. Thank you for any insights that ya'all can offer.


ppl please i'm just looking for a push in the right direction not for any 1 2 solve this problem for me. I'm getting pretty desperate as i have to hand this work in soon.


Dunno, it's been 15+ years since I last did any 68K work.

But the essence of arrays is to load the address of an array into an 'a' register, and load the subscript into a 'd' register.

Then look for the various indexed addressing modes, something like
move.b d1, a0(d0)

There might even be auto-incrementing modes, like
move.b d1, a0(d0+)


hi, thx for ur reply i really appreciate it. I think i have a working solution now ;) i will post it up in a while so that you can take a look.


here is a copy of the source code. its attached with this message.

nam	Stacks
	ttl	Program to demo stack use
	use	<oskdefs.d>			1. Include symbol definition file
Edition		equ	1			2. Identify the version
Typ_Lang		equ	(prgrm<<8) +Objct		3. The final code will be the object code
Attr_rev		equ	(ReEnt<<8) +0		4. And re-entrant with no revisions
Stacksize		equ	256			5. Initial user stack size
	psect	Stacks, Typ_Lang, Attr_Rev, Edition, Stacksize, Start

Clear_All:		dc.l	0,0,0,0,0,0,0,0

Word_Value:	dc.w	$2309, $ff34, 5212
Temp_Mem:	dc.l	0

Char_Array:	ds.b	100
bChar_Array:	dc.b	0

RevChar_Array:	ds.b	100
brevChar_Array:	dc.b	0

Correct:		dc.w	0
Correct_a:	ds.b	100

*Header placed here
Req_Input		dc.b	"Please type in some random characters:"
LenReq_Input	equ	*-Req_Input

Array:		dc.b	"This will reverse the characters:"
Len_Array:	equ	*-Array

Correct:		dc.w	"Correct:"
Len_Correct:	equ	*-Correct

*****************************Cursor Control**************************************
New_Line:	dc.b	C$LF, C$CR
LenNewLine:	equ	*-New_Line
*Macro starts here
		move.l	#1,d0
		move.l	\1,d1
		lea	\2(a6),a0
		os9	I$\3

*Program executable code begins here
Start:		INOUT	#LenNew_Line, New_Line, Write
		INOUT	#Req_Input, LenReq_Input, Write 
		INOUT	#100, Char_Array, ReadLn
		subi	#1,d1
		move.l	d1, bChar_Array (a6)
		lea	Char_Array(a6), a3
		move.l	bChar_Array (a6), d5
		subi.l	#1, d5 loop counter

Push_Loop:	move.b	(a3) +, d3
		move.b	d3, (sp) +
		dbra	d5, Push_Loop
		move.l	bChar_Array (a6), d5
		move.l	d5, brevChar_Array (a6)
		subi	#1,d5
		lea	revChar_Array (a6), a3

Pop_Loop		move.b	- (sp), (a3) +
		dbra	d5, Pop_Loop
Check1:	nop		break for debugger - note values

*This wil display the random characters in reverse order
		INOUT	#Array, Len_Array, Write
		INOUT	LenNew_Line, New_Line, Write
		INOUT	brevChar_Array (a6), revChar_Array, Write

*This will move 3 word values to user stack
		lea	Word_Value (a6), a3
		movem.l	Clear_All (a6), d0-d7
		move.w	(a3) +, d4
		move.w	d4, - (sp)
		move.w	(a3) +, d4
		move.w	d4, - (sp)
		move.w	(a3) +, d4
		move.w	d4, - (sp)
Check2:	nop		break for debugger - note values
		bsr	Add_word
*This will store the answer in memory
		move.w	(sp) +, Correct (a6)
Check3:	nop		break for debugger - note values

		movem.l	Clear_All (a6), d0-d7
		move.w	Correct (a6), d4
		bsr	Number_String
		move.b	(sp) +, (a3) +
		move.b	(sp) +, (a3) +
		move.b	(sp) +, (a3) +
		move.b	(sp) +, (a3) +
		INOUT	#LenNew_Line, New_Line, Write
		INOUT	#Correct, Len_Correct, Write
		INOUT	#4, Len_Correct, Write

*Exit System
		clr.w	d1	Ask Os9 to close down
		os9	F$Exit	the program cleanly exit the system

Add_Word:	nop
		movem.l	Clear_All (a6), d0-d7
		move.l	(a7) +, d4
		move.l	(a7) +, d5
		move.l	(a7) +, d5
		move.l	(a7) +, d5
		move.w	d5, - (a7)
		move.l	d4, - (a7)

Number_String	nop
		move.l	(a7) +, d3
		move.w	 d4, d5
		move.l	#3, d7
		divu	#$10, d5

		move.l	d5, d6
		and.l	#$0fff, d5
		and.l	#$ffff0000, d6
		swap	d6

		cmp.b	#9, d6
		bgt	Character
		add	#$30, d6
		move.b	d6, - (sp)
		bra	Loop2

Character	sub	#10, d6
		add	#$41, d6
		move.b	d6, - (sp)
		dbra	d7, Loop1

		move.l	d3, - (a7)

hey every 1 ive managed to solve this problem so i'm going 2 mark this as solved ;)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.