Download presentation
Presentation is loading. Please wait.
Published byAbel Washington Modified over 8 years ago
1
Assembly Programming Practical2
2
Initialising Variables (Recap) Initialising variables are done in the.data section Initialising variables are done in the.data section.code val1 dd 10 val2 dd 20
3
Initialising Variables (Recap) Variable Name Val1 dd Variable Type Value 10
4
Addition This is done in the.code section This is done in the.code section mov eax, val1 add eax, val2 Invoke WriteInt
5
Addition Explanation mov eax, val1 This code moves val1 to the eax register This code moves val1 to the eax register add eax, val2 This adds val2 to the eax which contains val1 (val1+val2) This adds val2 to the eax which contains val1 (val1+val2) Invoke WriteInt Writes the answer to the screan Writes the answer to the screan
6
Subtraction Similar to addition. Similar to addition. Replace add with sub Replace add with sub mov eax, val1 sub eax, val2 Invoke WriteInt
7
Multiplication This is done in the.code section This is done in the.code section mov eax, val1 mul val2 Invoke WriteInt
8
Multiplication Explanation mov eax, val1 Mul val2 This multiplies eax with val2 This multiplies eax with val2 Note the difference for multiplication Note the difference for multiplication Invoke WriteInt Writes the answer to the screan Writes the answer to the screan
9
Division This is done in the.code section This is done in the.code section mov eax, val1 div val2 invoke writeInt
10
Division Explanation mov eax, val1 div val2 This multiplies eax with val2 This multiplies eax with val2 Note the difference for multiplication Note the difference for multiplication Invoke WriteInt Writes the answer to the screen Writes the answer to the screen
11
Division By Negative If you want to divide by a negative number you use idiv If you want to divide by a negative number you use idiv
12
The Read Function ReadString is used to read in strings ReadString is used to read in strings ReadInt is used to read in values ReadInt is used to read in values
13
ReadString In the.data section you create In the.data section you create uname db 50 dup(0) uname db 50 dup(0) This creates the empty string uname This creates the empty string uname
14
ReadString In the.code section to call uname In the.code section to call uname mov edx, offset uname mov edx, offset uname – point dx, to address of input uname – point dx, to address of input uname invoke Readstring – read input as string into uname
15
ReadInt In the.data section you create In the.data section you create anumber dw ? anumber dw ? This creates the empty int anumber This creates the empty int anumber Don’t forget the question mark (?) Don’t forget the question mark (?)
16
ReadInt In the.code section to call anumber In the.code section to call anumber mov ax, anumber mov ax, anumber – copy anumber to AX register for display invoke Writeint invoke Writeint – display ax register as signed-integer
17
* Hint for Prac 2 A possible solution to the string reverse problem is labels for a loop that pushes a stack and pops it (will reverse the string). A possible solution to the string reverse problem is labels for a loop that pushes a stack and pops it (will reverse the string). Here is an example of pushing a stack and looping using a label. Similarly you need to pop the stack by reusing this code (creating label L2. On the next slide.
18
* Hint for Prac 2 mov ecx,nameSize; Push the name on the stack. mov esi,0 L1:movzx eax,source[esi]; get character push eax; push on stack inc esi Loop L1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.