Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

Some Assembly Language Examples


1. Describe the action of the following 68K assembly language instructions in RTL, register transfer language. That is, translate the assembly language syntax of the 68K instruction into the RTL notation that defines the action of the instruction.

a. M V OE 4000 b. M V OE c. M V OE d. M V OE e. M V OE f MV OE 5000 g. M V OE to D3 h. M V OE i. MV OE j. k. l. AD D AD D AD D

30,00 0040 D,4 0D 30,0 00D D,00 030 #00D 40,4 #0050 40,00 (0,3 A)D #2(0 1,A) (1,A) A)(2 D,1 2D #3D 1,4 (3,24 A)13

[00 [0] 40] 30 [4 [0 D] D] [0 [00 D] 30] [00 [0 30] D] [4 40 D] 00 [00]40 504 00 [3 [A] D] [0]

Copy contents of location 3000 to location Copy contents of D0 to D4 Copy contents of location 3000 to D0 Copy contents of D0 to location 3000 Copy the value 4000 to D4 Copy the value 4000 to location Copy contents of location pointed at by A0

[A] 1 [0] 2 Copy 12 to location pointed at by A0 [ A ] [ A ] Copy contents of location pointed at by A1 [2] [1] to location pointed at by A2 [ 1 [ 1 + D ] Add contents of D1 to D2 and put sum in D1 D] D][2 [ 4 [ 4 + 2 Add 13 to D4 and put sum in D4 D] D]1 [ 2 4 [ A ] Add contents of location pointed at by A3 to 13] [3] location 1234

2.

Explain why the following assembly language and RTL constructs are incorrect.

a. b. c. d. e. f.
3.

MV D,4 OE 3# MV [3,2 OE D]D MV (3,2 OE D)D [3 A +3 D] 0 [3 # D] 3 3 [3 D]

Can't move to a literal destination Operand of form [D3] not defined for 68K Operand of form (D3) not defined for 68K note (A3) is ok A0 is an address register should be [A0] Can't use # symbol in RTL Can't have literal as destination in RTL

Create a simple 68K program called A D R Your program should add together the numbers: 6, 4, 12, 16, 17, and 50. The DE. program is to be assembled with the 68K cross-assembler and then run on the 68K simulator (either Easy68K or the Teesside assembler/simulator). Run the binary file you have created in the simulation mode. A very simple program that does OG R $00 10 MV. Nb,0 OEB m1D ADB Nm2D D. ub,0 ADB Nm3D D. ub,0 ADB Nm4D D. ub,0 ADB Nm5D D. ub,0 ADB Nm6D D. ub,0 not use complex addressing modes and only uses very simple instructions is Lcto o teporm oain f h rga Gtfrtnme e is ubr Adi scn nme d n eod ubr Adi scn nme d n eod ubr Adi scn nme d n eod ubr Adi scn nme d n eod ubr Adi scn nme d n eod ubr
1/ 7

w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

Nb m1 Nb m2 Nb m3 Nb m4 Nb m5 Nb m6

SO TP OG R D. CB D. CB D. CB D. CB D. CB D. CB ED N

#20 $70 $00 20 6 4 1 2 1 6 1 7 5 0 $00 10

So eeuin tp xcto Lcto o tedt oain f h aa

Edo porm(n adeso frtisrcin n f rga ad drs f is ntuto)

4.

Give examples of valid 68K assembly language instructions that use: a. b. c. d. register-to-register addressing register-to-memory addressing memory-to-register addressing memory-to-memory addressing MV. D,2 OEB 0D MV. D,13 OEW 0$24 MV. $24D OEW 13,0 MV. (1,A) OEL A)(3

6.

By means of a memory map explain the effect of the following sequence of 68K assembly language directives. OG $0 R 60 D. 2 SL D. 2 CL D. '24 CB 13' Tm D. 6 ie CB Tp D. 6 o SB Bc EU 2 S1 Q I1 EU 3 T Q S1 D. I1Bc E SB T+S1

Ades drs 60 0 68 0 6C 0 mmr eoy 6D 0 6E 0 6F 0 60 1 61 1 67 1 235 +=) 6C 1

Nm ae

Vle au ??? ??? 0000 0002 3 1 3 2 3 3 3 4 6 ? ? 5

Cmet omn Rsre2x4=8bts eev ye Pt$0002i mmr u 0000 n eoy PtteAC srn '24 i u h SI tig 13' n

Tm ie Tp o S1 E

Ptbt vle6i mmr u ye au n eoy Rsre6btso soae eev ye f trg Bc i 2 S1 s I1i 3 T s Rsre5bts(T+S1i eev ye I1Bc s Nx fe lcto et re oain

7.

What would the following 68K assembly language fragment store at address $1002? OG $00 R 10 EU 5 Q D. 2 SB Starting point for following data etc is 1000 P is given the value 5. Using P is the same as using 5 Store two byte locations in memory location 1000 and 1001. Note that location 1000 is defined as Q
2/ 7

P Q

w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

Oe n

D. PQ CW +

Store a 16-bit word constant in memory location 1002. The value is P+Q=5+1000 = 1005

8.

What is wrong with each of the following 68K assembly language operations? a. b. c. d. e. f. g. h. MV OE ADB D. CPL M. MV. OEB D. SB ADW D. OG R BQB E. Tm,4 ep# #,3 1A D,9 0# #0,5 50D 12 , +A)D (2,3 #0 40 Lo_ op3 Ltrlcntb dsiain iea a' e etnto Cntd bt oeaino adesrgse a' o ye prto n drs eitr Cnthv ltrla dsiain a' ae iea s etnto Bgetbt mv i 25 igs ye oe s 5 Cnthv mlil oead wt D a' ae utpe prns ih S Cnthv penrmnigadesn md a' ae riceetn drsig oe Asml fr n # Sol b $0 seby om o . hud e 40 N . etnint bac isrcin o B xeso o rnh ntutos

9.

Answer the following questions about 68K assembler conventions. a. What is the effect of the assembler directive O G $ 0 ? R 40 Defines the address/location of the next data element of instruction to be loaded b. What is the effect of the assembler directive D . 2 ? SW 0 This directive creates 20 words or 40 bytes of storage from the current location. The next free location is 40 bytes on. c. What is the effect of the assembler directive D . 1 3 ? CW 24 The directive DC.W 1234 loads the decimal value 1234 (in binary form) into the current location and moves the location counter on by two bytes. d. What is the effect of the assembler directive D . $ 2 4 CW 13? The directive DC.W 1234 loads the hexadecimal value 1234 (in binary form) into the current location and moves the location counter on by two bytes. e. What is the effect of the + in the effective address ( 0 + A)? This indicates auto incrementing (more strictly post-incrementing). After the address register pointer has been used, its contents are incremented by 1, 2, or 4 depending on whether the operand was B, W, or L. f. What is the effect of the - in the effective address - A ) (0? This operand indicated predecrementing and is identical to auto-incrementing except that the address register is decremented before it is used to access the operand. g. Why A D . # , 0and A D L # , 0 DAL 4A D. 4D? Many modern 68K assemblers don't force you to use this convention. However, the original assembler required you to write ADDA, SUBA, MOVEA, and CMPA if the destination operand was an address register. This was done to remind you that address registers behaved differently to data registers.

11. Translate the following fragment of high-level language into 68K assembly language. I T=5 F TE X=4 HN EDI N_F Assume that T and X are in memory. Write a program to implement this fragment of code and run it on the 68K simulator. Select your own values for variables T and X. Use the simulator's trace mode to observe the behavior of the program. If we are going to turn this fragment of code into a program, we will need to include assembly overheads and data. One possible solution is:
w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e 3/ 7

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

OG R MV. OEB CPB M. BE N MV. OEB Ei SO xt TP OG R D. SB D. CB ED N

$0 40 TD ,0 #, 4T Ei xt #, 4X #20 $70 $00 10 3 2 0 $0 40

Sato porm tr f rga Gttevleo T e h au f I tevleo Teult 5 s h au f qa o I ntte lae f o hn ev Es md X=4 le ae Ei pitadtriainfrporm xt on n emnto o rga Ptdt i hr u aa n ee Ltsmk T=3o ti rn e' ae n hs u Ltsmk X =2 e' ae 0 Ls ln o po adsatn p freeuin at ie f rg n trig t o xcto

T X

13. The 68K can operate with byte, word and longword operands. What does this mean? Which type of operand do you use in any particular circumstance? The 68K's data and registers are 32 bits wide. A data operation may take part on the least-significant 8, 16, or the entire 32 bits of a register (as specified by a .B, >W, or .L suffix to the instruction). The operation ADD.B D0,D1 adds the least significant 8 bits of D0 to the least significant 8 bits of D1 and puts the result in the least-significant bits of D1. Note that bits 8 to 31 of register D1 are not affected by this instruction (some processors allows 8 bit operations but clear higherorder bits). If operations take one clock cycle, it doesn't matter which format you use. However, if byte or word operations are faster, then it make sense to use smaller data sizes. However, when dealing with natural 8-bit values such as ASCII characters, 8 bit operations are a good idea because you can read 8-bit values from memory and process them as 8-bit values.

24. Suppose you wish to pre-load memory with the value 1234 before executing a program. Which of the following operations is correct? a. b. c. d. e. D. CB D. CW D. CW D. SB MV. OEW #24 13 13 24 #24 13 $24 13 #24Lcto 13,oain Icret norc Cret orc Icret norc Icret norc Icret norc n #ad. wog o n B rn n # o ti rsre soae hs eevs trg ti lasmmr a rnie hs od eoy t utm

25. The register transfer language definition of M V . ( 2 + D is one of the following. CHECK OEB A),3 a. b. c. d. D 3 [A];[2 [2 +1 [2] A] A] [3 [A];[2 [2 +1 D] [2] A] A] [3 [A];[2 [2 +1 D] [2] A] A] [2 [2 +1 [3 [2; A] A] ; D] A]

26. When a parameter is passed to a subroutine by reference (i.e., not by value), a. b. c. d. e. f. the parameter can be put in an address register the address of the parameter can be put in an address register the address of the parameter can be pushed on the stack the parameter can be pushed on the stack parts a and d are correct parts b and c are correct CORRECT you pass an address

27. Consider the following code:


w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e 4/ 7

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

MV. X-A) OEW ,(7 MV. Y-A) OEL ,(7 BR S PR Q Cenu la_p a. b. c.

Ps X uh Ps Y uh Cl PR al Q Cenu tesak la p h tc

Why do you have to clean up the stack after returning from the subroutine? What code would you use to clean up the stack? Draw a memory map of the stack immediately before executing the RTS in the subroutine PQR.

a. The stack should be balanced in the sense that after you modify it, you should eventually reverse the modification. If a subroutine builds on top of the stack, you should restore the stack before returning. b. If you push a word and a longword on the stack, you move the stack pointer up by 6 bytes; that is [A7][A7] 6. You can undo this by adding 6 to the stack pointer with LEA 6(A7),A7.

c. Assume the stack is, say, $1000 before this code is executed. The first move, moves the stack up by 2 bytes to $0FFE. The second instruction moves the stack pointer up by 4 bytes to $0FFA. The subroutine call saves the 4-byte return address on the stack and pushes up the stack pointer to $0FF6 0F F6 0F FA 0F FE 10 00 Rt e YY YY X X 00 00 Rtr adespse o saka a1-i wr eun drs uhd n tc s 6bt od Ypse o saka a3-i wr uhd n tc s 2bt od Xpse o saka a1-i wr uhd n tc s 6bt od iiilsak nta tc

28. Write an assembly language program to reverse the bits of a byte. There are many ways of doing this. One technique is to shift the bits out of a register left (one-by one) and capture them in the eXtend bit. Then to shift the bits of another register right through the eXtend bit to move the bits in but in the reverse order; for example:
OG R MV. OEB MV. OEB CRL L. LLB S. RX. ORB DR BA SO TP D. CB $0 40 Ts,0 etD #,7 7D D 1 #,0 1D #,1 1D D,ht 7Sf #20 $70 %1000 1011

Sf ht

Gttesrn t rvre e h tig o ees UeD a alo cutrfr8cce s 7 s op one o yls UeD t cthtervre bt s 1 o ac h eesd is Sittebt oepaelf cthm bt hf h ye n lc et ac s i Rpa 8tms eet ie So eeuin tp xcto Ts srn et tig

Ts et

29. Explain why the following assembly language and RTL constructs are incorrect a. M V D , $ 4 OE 4#6 Cno ueltrla dsiainoead ant s iea s etnto prn b. M V ( 3 , 2 OE D)D Cno uedt rgse a pitr ant s aa eitr s one c. [ 3 A + 3 D] 0 Ti i RL Asm A sol b [0 hs s T. sue 0 hud e A] d. [ 3 # D] 3 Ti i RL Teasml lnug ltrlsmo i ntrqie wt altrl hs s T. h seby agae iea ybl s o eurd ih iea

32.

Assume that a string of ASCII characters is located in memory starting at location $2000. The string ends with the character 'Z'. Design and write a 68K assembly language program to count the number of 'E's, if any, in the string.
5/ 7

w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

Pitt frtcaatr on o is hrce StE cutrt 0 e s one o Lo:Ra caatra pitr op ed hrce t one Pitt nx caatr on o et hrce I caatr= ''te iceetE cutr f hrce = E hn nrmn s one I caatr= ''te so f hrce = Z hn tp Edlo n op OG R $0 40 LA E PrA t,0 A pit a srn 0 ons t tig CRB D L. 0 UeD a E cutr asm <25 s 0 s s one sue 5 Lo MV. (0+D op OEB A),1 Lo:rahca it D adudt pitr op ec hr no 1 n pae one CPB #Z,1 M. ''D ts frE et o'' BE N Nt oE i ntEte tyZ f o hn r ADB #,0 D. 1D i Ete iceetE cutr f hn nrmn s one Nt CPB #Z,1 oW M. ''D ts fr'' et o Z BE N Lo op Rpa utl''fud eet ni Z on SO TP #20 $70 Hl at OG R $00 10 Dmydt um aa Pr D. t SB 'CEEMNEMM' ADMEDEEEZ ED $0 N 40

33. Express the following sequence of 68K assembly language instructions in register transfer language and explain in plain English what each instruction does. a. L A E 4A)A (2,1 La A wt tecnet o A pu 4 od 1 ih h otns f 2 ls [1 [2 +4 A] A] b. M V A L A , 2 OE. 3A Copy the contents of A3 into A2 [2 [3 +4 A] A] c. M V . ( 1 , 3 OEB A)D Cp tebt a temmr lcto pitda b A it rgse D oy h ye t h eoy oain one t y 1 no eitr 3 [3 [3 +[A] D] D] [1] d. M V . # , A ) OEB 5(1 Cp teltrlvle5i t temmr lcto pitda b A oy h iea au n o h eoy oain one t y 1 [A] 5 [1] e. B S C AC B I tecrybti st jm t telcto AC f h ar i s e, up o h oain B I ( = 1 TE [C AC F C = ) HN P] B f. M V . ( 1 + - A ) OEB A),(3 Mv te bt pitda b A t te mmr lcto oe ls ta te lcto oe h ye one t y 1 o h eoy oain n es hn h oain pitda b A.IceetA b 1addceetS b 1 one t y 3 nrmn 1 y n ermn 3 y [3 [3 1 A] A] [A] [A] [3] [1] [1 [1 +1 A] A]

35. Suppose you are given an algorithm and asked to design and test a program written in 68K assembly language. How would
w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e 6/ 7

1/ 13/ 13

Som e Assem bl Language Exam pl s y e

you carry out this activity? Your answer should include considerations of program design and testing, and the necessary software tools. The answer to this question is long and depends on the available tools and the complexity of the algorithm to be coded. In principle, for a relatively small algorithm, you would turn the algorithm into pseudocode and then translate the pseudocode fragments into assembly language. To debug a program you can use a simulator such as EASy68k. You can step through instructions and observe the way in which registers change to see whether the code does something you didn't expect. Moreover, you can add breakpoints (places where execution stops) and run the code until a breakpoint is reached. This helps you when there are thousands of instructions to execute and step-by-step mode would be to slow.

w w scm . t ees. ac. uk/ user s/ u0000408/ C 68Kexam pl s. ht m w. SY/ e

7/ 7

You might also like