Part 1 0040 0041 0042 0043 ---0040 0040 0041 0042 0043 ---- 0002 0003 0004 0005 ---0040 0040 0041 0042 0043 ---0000 0000 754004 0003 754105 0006 754000 0009 754100 000C 754200 000F 0010 0012 0014 E4 F540 F541 F542 0016 754341 0019 0540 001B 1541 001D 854042 0020 AC02 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 $mod2051 ; int i,j,k ; char c; ; ;either one of these three methods i1 data 40h j1 data 41h k1 data 42h c1 data 43h ; dseg org 40h i2: ds 1 j2: ds 1 k2: ds 1 c2: ds 1 cseg ; i3 equ R2 j3 equ R3 k3 equ R4 c3 equ R5 i3_ data 2 j3_ data 3 k3_ data 4 c3_ data 5 ;-----------------------------------------; int i,j,k; ; char cc; dseg org 40h i: ds 1 j: ds 1 k: ds 1 cc: ds 1 cseg org 0 ;-----------------------------------------; i = 4; ; j = 5; ; mov i,#4 mov j,#5 ;-----------------------------------------; i = 0; ; j = 0; ; k = 0; ; mov i,#0 mov j,#0 mov k,#0 ; or (better!) clr a mov i,a mov j,a mov k,a ;-----------------------------------------; cc = 'A' ; mov cc,#'A' ;-----------------------------------------; i++; ; j--; ; inc i dec j ;-----------------------------------------; k = i; ; mov k,i mov k3,i3_ ;<-! 1 0022 E540 0024 2541 0026 F542 0028 002A 002B 002D E540 C3 9541 F542 002F 0031 0034 0035 E540 8541F0 A4 F542 0037 0039 003C 003D E540 8541F0 84 F542 003F 0041 0044 0045 E540 8541F0 84 85F042 0048 434320 004B 430520 004E 5343DF 0051 5305DF 0054 E540 0056 B54101 0059 00 005A 005A EA 005B B50301 005E 00 005F 005F 0061 0064 0066 0067 E540 B54102 8001 00 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 ;-----------------------------------------; k = i + j; ; mov a,i add a,j mov k,a ;-----------------------------------------; k = i - j; ; mov a,i clr c subb a,j mov k,a ;-----------------------------------------; k = i*j; ; mov a,i mov b,j mul ab mov k,a ;-----------------------------------------; k = i/j; ; mov a,i mov b,j div ab mov k,a ;-----------------------------------------; k = i%j; ; mov a,i mov b,j div ab mov k,b ;-----------------------------------------; cc = cc | 0x20h /*lowercase it*/ ; orl cc,#20h orl c3_,#20h ;<-! ;-----------------------------------------; cc = cc & 0xdf /*uppercase it*/ ; anl cc,#0dfh anl c3_,#0dfh ;<-! ;-----------------------------------------; if (i==j) { ... } ; mov a,i cjne a,j,l1 nop ;...; l1: ; mov a,i3 cjne a,j3_,l1_3 ;<-! nop ;...; l1_3: ;-----------------------------------------; if (i!=j) {...} ; mov a,i cjne a,j,l2 sjmp l3 l2: nop ;...; l3: 2 0067 0069 006C 006E 0071 0073 0074 E540 B54102 8006 B40502 8001 00 0074 0076 0079 007B 007E 007F E540 B54102 8003 B40501 00 007F 0081 0082 0084 0086 0087 E540 C3 940A 5001 00 0087 008A 008C 008F 0091 0092 0094 0096 754000 E540 B40A02 8005 00 0540 80F4 0096 0098 009B 009D 009E 009F 00A1 7A00 BA0A02 8004 00 0A 80F7 00 ---0044 0064 ---- 00A2 00A4 00A7 00A8 00A9 00AA 00AC 00AD 00AE 00B0 00B4 00B6 7844 9000B0 E4 93 F6 600A 08 A3 80F7 50657465 7200 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 ;-----------------------------------------; if ((i!=j) && (i!=5)) {...} ; mov a,i cjne a,j,l5 sjmp l7 l5: cjne a,#5,l6 sjmp l7 l6: nop ;...; l7: ;-----------------------------------------; if ((i==j) || (i==5)) {...} ; mov a,i cjne a,j,l8 sjmp l9 l8: cjne a,#5,l10 l9: nop ;...; l10: ;-----------------------------------------; if (i<10) {...} ; mov a,i clr c subb a,#10 jnc l11 nop ;...; l11: ;-----------------------------------------; for (i=0;i!=10;i++) {...} ; mov i,#0 l12: mov a,i cjne a,#10,l13 sjmp l14 l13: nop ;...; inc i sjmp l12 l14: ; mov i3,#0 l12_3: cjne i3,#10,l13_3 ;<-! sjmp l14_3 l13_3: nop ;...; inc i3 sjmp l12_3 l14_3: nop ;-----------------------------------------; char s[32],t[32]; ; dseg s: ds 32 t: ds 32 cseg ;-----------------------------------------; strcpy(s,"Peter"); ; mov r0,#s mov dptr,#m1 l15: clr a movc a,@a+dptr mov @r0,a jz l16 inc r0 inc dptr sjmp l15 m1: db 'Peter',0 204 l16: 3 00B6 00B8 00BA 00BB 00BC 00BE 00BF 00C0 00C2 7864 7944 E7 F6 6004 08 09 80F8 00C2 11C6 00C4 8005 00C6 7832 00C8 D8FE 00CA 22 00CB 00CB 7832 00CD 11D1 00CF 8003 00D1 D8FE 00D3 22 00D4 00D4 00D6 00D8 00DA 00DC A841 A942 11DE F540 8009 00DE 00DF 00E0 00E1 00E3 00E4 00E5 00E6 E8 C3 99 4002 E8 22 E9 22 00E7 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 ;-----------------------------------------; strcpy(t,s); ; mov r0,#t mov r1,#s l17: mov a,@r1 mov @r0,a jz l18 inc r0 inc r1 sjmp l17 l18: ;-----------------------------------------; delay1(); /*delay ~100 cylces*/ ; void delay1(void); ; acall delay1 sjmp l19 ; delay1: mov r0,#50 djnz r0,$ ret ; l19: ;-----------------------------------------; delay2(50); /*delay ~2*argument cycles*/ ; void delay2(int); ; mov r0,#50 acall delay2 sjmp l20 ; delay2: djnz r0,$ ret ; l20: ;-----------------------------------------; i = max(j,k); ; int max(int,int); ; mov r0,j mov r1,k acall max mov i,a sjmp l22 ; max: mov a,r0 clr c subb a,r1 jc l21 mov a,r0 ret l21: mov a,r1 ret ; l22: end 4 Part 2 ---- 0000 0000 11DA 0002 80FE 0004 0004 0005 0006 0007 0008 0009 0009 000A 000D 000F 0010 0013 0015 0016 0019 001B 001B E4 FA FB FC 22 0C BC640E 7C00 0B BB3C08 7B00 0A BA3C02 7A00 22 001C 001C 001D 001F 0021 0023 0024 0026 0028 002A 002B 002D EA 112E 743A 119C EB 112E 742E 119C EC 112E 22 002E 002E 0031 0032 0034 0036 0038 003A 003C 75F00A 84 2430 119C E5F0 2430 119C 22 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 $mod2051 ;-----------------------------------------; store times in binary in registers ; mm equ R2 ss equ R3 hh equ R4 cseg ;-----------------------------------------; put your main function here! ; eg: ; org 0h ; ; ; ; ; or ; acall mov acall init_lcd a,#'A' put_lcd acall polling_loop jmp $ ;-----------------------------------------; zero_clock(); ; zero_clock: clr a mov mm,a mov ss,a mov hh,a ret ;-----------------------------------------; inc_clock(); ; inc_clock: inc hh ;add one to the hundreds cjne hh,#100,inc_clock_end mov hh,#0 inc ss ;add one to the seconds cjne ss,#60,inc_clock_end mov ss,#0 inc mm cjne mm,#60,inc_clock_end mov mm,#0 inc_clock_end: ret ;-----------------------------------------; display_clock(); ; display_clock: mov a,mm acall put_digits mov a,#':' acall putch mov a,ss acall put_digits mov a,#'.' acall putch mov a,hh acall put_digits ret ; put_digits: mov b,#10 div ab add a,#'0' acall putch mov a,b add a,#'0' acall putch ret 5 003D 003E 0040 0042 0043 0045 0045 0047 0049 004B 004D E6 6005 119C 08 80F8 004E 0050 0053 0055 0058 005A 005B 005C 005E 005E 0060 11B7 B40A02 80F9 B40D02 8004 F6 08 80F0 0061 0061 0064 0067 006A 006D 0070 0072 0073 0073 0074 0077 0079 0079 007B 007C 007E 0081 0083 0086 0088 008B 008D 008E 0091 0093 0094 0094 0098 740D 119C 740A 119C 22 7600 22 53890F 438920 758DFD 758BFD 759850 D28E 22 E4 900094 C2B4 C0E0 93 D2B5 1200C2 F590 1200C2 C2B5 1200C2 D0E0 04 B408E8 D2B4 22 30303038 0801060C 009C 009C 119F 009E 22 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97 98 99 100 101 102 103 104 105 106 107 109 110 111 112 113 114 115 116 117 118 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 ;-----------------------------------------; puts(s); ; r0 points to zero terminated string ; a and r0 are altered by this routine ; puts: mov a,@r0 jz puts_end acall putch inc r0 sjmp puts puts_end: mov a,#0dh acall putch mov a,#0ah acall putch ret ;-----------------------------------------; gets(s); ; r0 points to memory to place string ; nul will be added to string ; CR will terminate string LF are ignored ; a and r0 are altered by this routine gets: acall getch cjne a,#0ah,gets_1 sjmp gets gets_1: cjne a,#0dh,gets_2 sjmp gets_end gets_2: mov @r0,a inc r0 sjmp gets gets_end: mov @r0,#0 ret ;-----------------------------------------; init_rs232(); init_rs232: anl tmod,#0fh ;zero timer 1 orl tmod,#20h ;set mode 2 mov th1,#0fdh ;reload value mov tl1,#0fdh ;initial value mov scon,#50h ;serial mode setb tr1 ;start timer1 ret ;-----------------------------------------; init_lcd(); init_lcd: clr a mov dptr,#init_table clr P3.4 ;control not data init_lcd_1: push acc movc a,@a+dptr setb P3.5 call delay mov P1,a call delay clr P3.5 call delay pop acc inc a cjne a,#8,init_lcd_1 setb P3.4 ;data not control ret init_table: db 30h,30h,30h,38h,08h,01h,06h,0ch 140 141 142 143 144 145 146 ;-----------------------------------------; putch(); ; putch: acall put_rs232 ; acall put_lcd ret 6 009F 009F 00A1 00A4 00A6 F599 3099FD C299 22 00A7 00A7 00A9 00AC 00AE 00B1 00B3 00B6 D2B5 1200C2 F590 1200C2 C2B5 1200C2 22 00B7 00B7 11BA 00B9 22 00BA 00BA 00BD 00BF 00C1 3098FD C298 E599 22 00C2 7832 00C4 D8FE 00C6 22 DBFF 00C7 00C7 C28C 00C9 5389F0 00CC 438901 00CF C28D 00D1 758CDB 00D4 758AFF 00D7 D28C 00D9 22 00DA 00DA 00DC 00DE 00DE 00E1 00E3 00E5 00E7 00E9 00E9 00EC 00EE 00F0 1161 11C7 309808 11B7 111C 740D 119C 308DF2 11C7 1109 80EC 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 ;-----------------------------------------; put_rs232(); ; put_rs232: mov sbuf,a jnb ti,$ ;wait for it to go clr ti ret ;-----------------------------------------; put_lcd(); ; put_lcd: setb P3.5 call delay mov P1,a call delay clr P3.5 call delay ret ;-----------------------------------------; getch(); ; getch: acall get_rs232 ret ;-----------------------------------------; get_rs232(); ; get_rs232: jnb ri,$ clr ri mov a,sbuf ret ;-----------------------------------------; delay(); /*~100 cycles*/ ; delay: mov r0,#50 djnz r0,$ ret ;-----------------------------------------; start_timer(); /*1/100 second*/ ; use timer 0 TICS equ 0ffffh-9216 start_timer: clr tr0 ;stop the timer anl tmod,#0f0h ;zero timer orl tmod,#01h ;set mode 1 clr tf0 ;clear flag mov th0,#(TICS/256) mov tl0,#(TICS mod 256) setb tr0 ;start the timer ret ;-----------------------------------------; code to increment our clock every ; 1/100 sec and check whether a character ; has arrived at the rs232 interface, ; in which case display current clock ; uses polling! polling_loop: acall init_rs232 acall start_timer check_rs232: jnb ri,check_timer acall getch acall display_clock mov a,#0dh ;carriage return acall putch check_timer: jnb tf0,check_rs232 acall start_timer acall inc_clock sjmp check_rs232 ; 7 Part 3 DBFF ---0040 0040 ---- 0000 0000 116B 000B 000B 8018 0023 0023 801C 0025 0025 0027 0029 002C 002F 0031 0034 C28C C28D 758CDB 758AFF D28C 12009C 32 0035 0035 0038 003A 003C 003D 003E 0040 209906 C298 A699 08 32 C299 32 0041 0041 0044 0046 0048 004A 004C 004E 004F 0051 20990B C298 C0E0 E599 11DA D0E0 32 C299 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 $mod2051 ; TICS equ 0ffffh-9216 ;-----------------------------------------; store times in binary in registers ; mm equ R2 ss equ R3 hh equ R4 ; dseg org 40h buffer: ds 32 cseg ;-----------------------------------------; uses interrupts ! ; choose which rtne you want to see working ; swap to the correct ISR as well ; org 0h ; acall capture_rs232 ; or perhaps ; acall start_timer ; or perhaps acall rs232_to_lcd ; org 0bh sjmp clock_interrupt org 23h ; sjmp capture_rs232_interrupt ; or perhaps sjmp rs232_to_lcd_interrupt ;-----------------------------------------; clock interrupt, start clock going for ; another 1/100 of a second ; clock_interrupt: clr tr0 ;stop timer clr tf0 ;clear flag mov th0,#(TICS/256) mov tl0,#(TICS mod 256) setb tr0 ;start the timer call inc_clock reti ;-----------------------------------------; capture rs232 intrpt, put data where r0 ; points, then increment r0 ; capture_rs232_interrupt: jb ti,l1 clr ri mov @r0,sbuf inc r0 reti l1: clr ti reti ;-----------------------------------------; rs232 to lcd intrpt, display data on lcd ; rs232_to_lcd_interrupt: jb ti,l2 clr ri push acc mov a,sbuf acall put_lcd pop acc reti l2: clr ti reti 8 0052 0052 0054 0057 005A 005D 0060 0063 0065 0067 0069 7840 53890F 438920 758DFD 758BFD 759850 D28E D2AF D2AC 80FE 006B 006B 006D 0070 0073 0076 0079 007C 007E 0080 0082 11B4 53890F 438920 758DFD 758BFD 759850 D28E D2AF D2AC 80FE 0084 0084 0086 0089 008C 008E 0091 0094 0096 0098 009A C28C 5389F0 438901 C28D 758CDB 758AFF D28C D2AF D2A9 80FE 009C 009C 009D 00A0 00A2 00A3 00A6 00A8 00A9 00AC 00AE 00AE 0C BC640E 7C00 0B BB3C08 7B00 0A BA3C02 7A00 22 00AF 7832 00B1 D8FE 00B3 22 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 ;-----------------------------------------; capture serial data - put into memory ; capture_rs232: mov r0,#buffer anl tmod,#0fh ;zero timer 1 orl tmod,#20h ;set mode 2 mov th1,#0fdh ;reload value mov tl1,#0fdh ;initial value mov scon,#50h ;serial mode setb tr1 ;start timer1 setb ea setb es sjmp $ ;-----------------------------------------; capture serial data - put to lcd ; rs232_to_lcd: acall init_lcd anl tmod,#0fh ;zero timer 1 orl tmod,#20h ;set mode 2 mov th1,#0fdh ;reload value mov tl1,#0fdh ;initial value mov scon,#50h ;serial mode setb tr1 ;start timer1 setb ea setb es sjmp $ ;-----------------------------------------; start_timer(); /*1/100 second*/ ; use timer 0 ; start_timer: clr tr0 ;stop the timer anl tmod,#0f0h ;zero timer orl tmod,#01h ;set mode 1 clr tf0 ;clear flag mov th0,#(TICS/256) mov tl0,#(TICS mod 256) setb tr0 ;start the timer setb ea setb et0 sjmp $ ;-----------------------------------------; inc_clock(); inc_clock: inc hh ;add one to the hundreds cjne hh,#100,inc_clock_end mov hh,#0 inc ss ;add one to the seconds cjne ss,#60,inc_clock_end mov ss,#0 inc mm cjne mm,#60,inc_clock_end mov mm,#0 inc_clock_end: ret ;-----------------------------------------; delay(); /*~100 cycles*/ delay: mov r0,#50 djnz r0,$ ret 9 00B4 00B4 00B5 00B8 00BA 00BA 00BC 00BD 00BF 00C1 00C3 00C5 00C7 00C9 00CB 00CC 00CF 00D1 00D2 00D2 00D6 00DA 00DA 00DC 00DE 00E0 00E2 00E4 00E6 E4 9000D2 C2B4 C0E0 93 D2B5 11AF F590 11AF C2B5 11AF D0E0 04 B408EB D2B4 22 30303038 0801060C D2B5 11AF F590 11AF C2B5 11AF 22 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 ;-----------------------------------------; init_lcd(); init_lcd: clr a mov dptr,#init_table clr P3.4 ;control not data init_lcd_1: push acc movc a,@a+dptr setb P3.5 call delay mov P1,a call delay clr P3.5 call delay pop acc inc a cjne a,#8,init_lcd_1 setb P3.4 ;data not control ret init_table: db 30h,30h,30h,38h,08h,01h,06h,0ch 155 156 157 158 159 160 161 162 163 164 165 ;-----------------------------------------; put_lcd(); put_lcd: setb P3.5 call delay mov P1,a call delay clr P3.5 call delay ret end 10