3 1 ADDITION SUBTRACTION OF INTEGERS 1 ADDITION
3. 1: ADDITION & SUBTRACTION OF INTEGERS 1
ADDITION AND SUBTRACTION • Registers are used to hold intermediate data. • Library subroutine to display the contents of the registers on the screen. • Title Add and subtract (Addsub. asm) ; This program add and subtracts 32 -bit integers INCLUDE Irvine 32. inc. code main PROC mov eax, 10000 h ; EAX = 10000 h add eax, 40000 h ; EAX = 50000 h sub eax, 20000 h ; EAX = 30000 h call Dump. Regs ; display registers exit main ENDP END main 2
ADDITION AND SUBTRACTION • Title directive marks the entire line as comment. • Title Add and subtract (Addsub. asm) • Comments are also ignored by assembler • ; This program add and subtracts 32 -bit integers • INCLUDE irvine 32. inc directive • Include directive copies necessary definitions and setup information from the text file named Irvine 32. inc, located in assembler’s INCLUDE directory. • . Code directive • It marks the beginning of the code segment, where all executable statements in a program are located. 3
ADDITION AND SUBTRACTION • PROC directive identifies the beginning of a procedure. • main PROC • Move instruction copies the integer 10000 h to EAX register. The first operand EAX is called the destination operand, the second is called as source operand. • mov eax, 10000 h ; EAX = 10000 h • ADD instruction adds 40000 h to the EAX register. • Add eax, 4000 h ; EAX = 50000 h • SUB instruction subtracts 20000 h from the EAX register. • Sub eax, 20000 h ; 30000 h • CALL statement calls a procedure that displays the current values of the CPU registers. • Call Dump. Regs ; display register’s value 4
ADDITION AND SUBTRACTION • Exit statement indirectly calls a predefined MS-Windows function that halts the program. • exit; • ENDP directive marks the end of the main procedure. • main ENDP • END directive marks the last line of program and identifies the name of program’s startup procedure. 5
- Slides: 5