Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views1 page

Tong Hieu 2

The document describes a program that takes in two numbers as input, calculates the sum and difference of the numbers, and outputs the results. It handles negative numbers and results greater than 10 for the sum. The program demonstrates using traps to get input and output, basic arithmetic operations, conditional branching, and constants.

Uploaded by

anhngoc.cgt.2012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Tong Hieu 2

The document describes a program that takes in two numbers as input, calculates the sum and difference of the numbers, and outputs the results. It handles negative numbers and results greater than 10 for the sum. The program demonstrates using traps to get input and output, basic arithmetic operations, conditional branching, and constants.

Uploaded by

anhngoc.cgt.2012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1 VD: TỔNG HIỆU 2

2 .ORIG X3000
3 LD R6, ASCII ; lay gia tri luu trong label "ASCII" luu vao R6
4 LD R5, NEGASCII ; ___________________________ "NEGASCII" luu vao R5
5
6 TRAP X23 ; lenh nhap 1 ky tu -> luu vao R0
7 ADD R1, R0, X0 ; luu gtri vua nhap vao R1
8 ADD R1, R0, R5 ; dua gia tri ve he thap phan
9
10 TRAP X23
11 ADD R0, R0, R5 ; dua gtri vua nhap ve he thap phan roi luu vao R5
12 ADD R2, R0, R1 ; tong 2 so vua nhap
13
14 NOT R0, R0 ; lay bu 1 R0 roi luu lai vao R0
15 ADD R0, R0, #1 ; lay bu 2 R0
16 ADD R3, R0, R1 ; hieu 2 so -> luu vao R3
17
18 LEA R0, MESG ; lay chuoi MESG luu vao R0
19 TRAP X22 ; lenh xuat chuoi trong R0
20
21 LD R0, HIEU10 ;
22 ADD R4, R0, R2 ; kiem tra tong co lon hon 10 bang hieu voi 10
23 BRZP CHUC ; neu ket qua hieu ra duong -> xuong label "CHUC"
24 ADD R0, R2, R6 ; dua tong trong R2 ve ma Ascii
25 TRAP X21 ; lenh xuat gia tri trong R0 ra Console
26
27 TIEPTUC LD R0, DOWN ;
28 TRAP X21 ; xuat ky tu xuong dong
29
30 LEA R0, MESG2 ;
31 TRAP X22 ; xuat chuoi MESG2
32
33 ADD R0, R3, #0 ; luu R3 vao R0
34 BRN AM ; neu hieu hai so la am -> xuong label "AM"
35 ADD R0, R3, R6 ; dua hieu trong R3 ve ma Ascii
36 TRAP X21 ; xuat
37
38 HALT ; lenh ket thuc chuong trinh
39
40 ; trang 1
41
42
43 CHUC LD R0, KYTU1 ; dua ky tu ma Ascii "1" vao R0
44 TRAP X21 ; xuat
45 ADD R0, R4, R6 ; dua hieu 10 trong R4 ve ma Ascii
46 TRAP X21 ; xuat
47 BR TIEPTUC ; re nhanh vo dieu kien den "TIEP TUC"
48
49 AM LD R0, DAUTRU ;
50 TRAP X21 ; xuat ky tu dau "-"
51 ADD R0, R3, #-1 ;
52 NOT R0, R0 ; lay bu 2 nguoc -> lay gia tri tuyet doi cua hieu
53 ADD R0, R0, R6 ; dua ve ma Ascii
54 TRAP X21 ; xuat
55
56 HALT ; ket thuc
57
58 ASCII .FILL X30 ; hang so dua he thap phan ve ma Ascii
59 NEGASCII .FILL XFFD0 ; hang so dua ma Ascii ve he thap phan
60 DOWN .FILL X0D ; ma Ascill cua ky tu xuong dong
61 HIEU10 .FILL #-10 ;
62 KYTU1 .FILL X31 ; ky tu ma Ascii "1"
63 DAUTRU .FILL X2D ; ky tu ma Ascii dau "-"
64 MESG .STRINGZ "TONG HAI SO LA " ;
65 MESG2 .STRINGZ "HIEU HAI SO LA " ; chuoi luu trong label
66
67 .END ; khong con lenh nao sau lenh nay
68

You might also like