1 / 18

Assembly Programming

Practical2. Assembly Programming. Initialising Variables (Recap). Initialising variables are done in the .data section .code val1 dd 10 val2 dd 20. Initialising Variables (Recap). Val1. dd. 10. Variable Name. Variable Type. Value. Addition. This is done in the .code section

clovis
Download Presentation

Assembly Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Practical2 Assembly Programming

  2. Initialising Variables (Recap) • Initialising variables are done in the .data section .code val1dd 10 val2dd 20

  3. Initialising Variables (Recap) Val1 dd 10 Variable Name Variable Type Value

  4. Addition • This is done in the .code section moveax, val1 add eax, val2 InvokeWriteInt

  5. Addition Explanation moveax, val1 • This code moves val1 to the eax register add eax, val2 • This adds val2 to the eax which contains val1 (val1+val2) Invoke WriteInt • Writes the answer to the screan

  6. Subtraction • Similar to addition. • Replace add with sub moveax, val1 subeax, val2 InvokeWriteInt

  7. Multiplication • This is done in the .code section moveax, val1 mulval2 InvokeWriteInt

  8. Multiplication Explanation moveax, val1 Mulval2 • This multiplies eax with val2 • Note the difference for multiplication Invoke WriteInt • Writes the answer to the screan

  9. Division • This is done in the .code section moveax, val1 movebx, val2; stores val2 in ebx subedx, edx divebx

  10. Division Explanation moveax, val1 movebx, val2 Moves val2 into ebx subedx, edx divebx Divides eax by ebx

  11. Division By Negative • If you want to divide by a negative number you use idiv

  12. The Read Function • ReadStringis used to read in strings • ReadInt is used to read in values

  13. ReadString • In the .data section you create • unamedb 50 dup(0) • This creates the empty string uname

  14. ReadString • In the .code section to call uname movedx, offset uname • point dx, to address of input uname invokeReadstring • read input as string into uname

  15. ReadInt • In the .data section you create anumberdd? • This creates the empty intanumber • Don’t forget the question mark (?)

  16. ReadInt invoke Readint Reads in the integer from command prompt movanumber, eax copy the value from command prompt into the variable anumber

  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). • 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 • movecx,nameSize ; Push the name on the stack. • mov esi,0 • L1: movzxeax,source[esi] ; get character • push eax ; push on stack • incesi • Loop L1

More Related