All pastes #167724 Raw Edit

Something

public text v1 · immutable
·published 2006-09-12 08:16 UTC
rendered paste body
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                             ;
;       Insert   Insert a record in the list                                  ;
;                Acquire arecord from the freelist, read data from user then  ;
;                link it into the list                                        ;
;                                                                             ;
;       Entry   jal insert                                                    ;
;                                                                             ;
;       uses    r1,r2                                                         ;
;                                                                             ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
		.seg		Code
insMsg		.ascii		"City already exits\r\n\0"
insCity		.ascii		"City: \0"
insCount	.ascii		"Country: \0"
insLat		.ascii		"Latitude: \0"
insLong		.ascii		"Longitude: \0"
		.align		2

		.seg		Data
InsertR31 	.space		4
InsertR3	.space		4
InsertR4	.space		4
InsertR5	.space		4

		.seg		Code
insert		sw		InsertR31,r31		;Save r31
		sw		InsertR3,r3		;Save r3
		sw		InsertR4,r4		;Save r4
		sw		InsertR5,r5		;Save r5
		
		lw		r3,freeList		;r3=->first record in freeList

		addui		r1,r0,insCity		
		jal		StrPut
		addui		r1,r3,ofsName
		addui		r2,r0,20
		;ofsCountry-ofsName
		jal		StrGet			;Read city
		addui		r1,r3,ofsName
		jal		find
		bnez		r1,InsertDup				

		addui		r1,r0,insCount
		jal		StrPut
		addui		r1,r3,ofsCountry
		addui		r2,r0,20
		;ofsLat-ofsCountry
		jal		StrGet			;Read country

		addui		r1,r0,insLat
		jal		StrPut
		addui		r1,r3,ofsLat
		addui		r2,r0,4
		;ofsLong-ofsLat
		jal		StrGet			;Read Lat
		jal		StrToInt		;Convert Lat to int
		sw		ofsLat(r3),r1

		addui		r1,r0,insLong
		jal		StrPut
		addui		r1,r3,ofsLong
		addui		r2,r0,4
		;52-ofsLong
		jal		StrGet			;Read Long
		jal		StrToInt		;Convert Long to int
		sw		ofsLong(r3),r1

InsertAddList	lw		r4,cityList		;r4=first record in cityList
		addi		r5,r0,cityList		;r5=->first record in cityList

InsertWhile	beqz		r4,InsertRecord		;r4=->null
	
		addi		r1,r4,ofsName		;r1=->CityRecord.CityName
		addi		r2,r3,ofsName		;r2=->CityName		
		jal		StrCmp			;Compare CityName, CityRecord.CityName	

		;beqz		r1,InsertDup		;	

		sgt		r1,r1,r0		;s>0
		bt		r1,InsertRecord	

InsertNextRec	add		r5,r0,r4		;r5=->Current record
		lw 		r4,ofsNext(r4)		;r4=->CityList.next		
		j		InsertWhile

InsertRecord	lw		r2,(r3)			;r2=->freeList.next
		sw		freeList,r2		;freeList=->freeList.next
		sw		ofsNext(r5),r3		;PreviousRecord->NewRecord
		sw		ofsNext(r3),r4		;NewRecord->NextRecord
		j		InsertEnd		

InsertDup	addui		r1,r0,insMsg		
		jal		StrPut			;Print "City already exits"

InsertEnd	lw		r31,InsertR31		;Restore r31
		lw		r3,InsertR3		;Restore r3
		lw		r4,InsertR4		;Restore r4
		lw		r5,InsertR5		;Restore r5		

		jr		r31