Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *input***************************
- *read a number through keyboard*
- MOVE.B #13,D0 ; task 13: display a string without CRLF
- LEA MES0,A1 ; assign address of MES to A1
- TRAP #15
- MOVE.B #4, D0 ; task 4: load number to D1.L
- TRAP #15
- TRAP #15
- MOVE.B #3,D0 ; task 3: display signed number in D1.L
- TRAP #15
- ********************************
- *modulo*************************
- MOVE.L D1,D3 ; store input number in D3.L
- CLR.L D1 ; clear D1
- DIVU Y,D3 ; compute modulo and remainder of D3/Y
- ; remainder is stored in higher bits of D3.L
- ; quotient is stored in lower bits of D3.L
- SWAP D3 ; swap content of lower bits and higher bits
- ; now, modulo is stored in the lower bit of D3.L
- MOVE.W D3,D1 ; move modulo to D1
- MOVE.B #14,D0 ; display MES2
- LEA MES2,A1
- TRAP #15
- MOVE.B #3,D0 ; display modulo in D1.L
- TRAP #15
- MOVE.B #14,D0 ; newline
- LEA NEWLINE,A1
- TRAP #15
- ********************************
- *array**************************
- *random access of an array*
- LEA SOMEARRAY,A2 ; get address of SOMEARRAY
- MOVE.W (A2),D1 ; get SOMEARRAY[0]
- MOVE.B #3,D0 ; display SOMEARRAY[0]
- TRAP #15
- MOVE.B #14,D0 ; newline
- LEA NEWLINE,A1
- TRAP #15
- ADD.W #6,A2 ; fourth element
- ; since the array is initialized with DC.W, each element takes 2 bytes
- ; so, the address of the 4th element= address of the 1st element + (2 bytes)*(4-1)
- MOVE.W (A2),D1 ; get SOMEARRAY[3]
- MOVE.B #3,D0 ; display SOMEARRAY[3]
- TRAP #15
- ********************************
- SIMHALT
- * Put variables and constants here
- NEWLINE DC.B $D,$A,0
- MES0 DC.B 'Input the size of the array: ',0 ; Here, 0 indicates the end of a string, which is similar to '\0' in c-style strings
- MES1 DC.B 'Your input is: ',0
- Y DC.W 10
- MES2 DC.B 'The modulo is: ',0
- SOMEARRAY DC.W 2,3,8,1,6,5,4
- END START ; last line of source
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement