1 / 12

An “interactive” application

An “interactive” application. An introduction to “structured” assembly language programming. A human-computer dialogue. Typical pattern: Computer asks a question Human types in a response Simple example: Computer says: How many dots? Human replies: 125 <ENTER>

ncouey
Download Presentation

An “interactive” application

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. An “interactive” application An introduction to “structured” assembly language programming

  2. A human-computer dialogue • Typical pattern: • Computer asks a question • Human types in a response • Simple example: • Computer says: How many dots? • Human replies: 125 <ENTER> • Computer does as requested.

  3. Standard C functions • How can we do input/output in assembly? • We can call standard C library functions • But we need to know their “prototypes” • For output (where STDOUT equals 1): write( STDOUT, &query, sizeof( query ) ); • For input (where STDIN equals 0): read( STDIN, &buffer, sizeof( buffer ) );

  4. Structured programming • A discipline for faster program design • Idea: break a big task into simple pieces • It’s known as “task decomposition” • We can use a diagram to illustrate it • Diagram is called a “Structure Chart”

  5. Structure Chart example main obtain_input process_data print_output

  6. Code for the ‘main’ function .section .text main: call obtain_input call process_data call print_output ret .globl main

  7. Stubs • You can write empty ‘stubs’ (for testing) obtain_input: ret process_data: ret print_output: ret • Now you can ‘test’ your skeleton program (e.g. assemble, link, and execute)

  8. Add details for each ‘stub’ • First write your final subroutine, so you can see “something” on the screen • You can use ‘dummy’ data temporarily • Get it working correctly (debugged) • Then you can focus on you next ‘stub’

  9. Main algorithm • Converting user’s input-string to a number • That is “the hard part” in this example • Idea: “scan” the array of character-codes • Test each code (to see if it’s a valid digit) • It must lie between ‘0’ and ‘9’ (ascii codes) • If code is not not valid, the scanning stops • Otherwise, adjust the accumulated total

  10. Some new directives .ascii .asciz .long .byte .space

  11. Some new CPU instructions sub dec cmp jg jl jz jnz movzx loop imul

  12. Exercise with ASCII codes • See what happens if you change the ascii code used for as value of the ‘dot’ variable • Try using ascii value 7 • Try using ascii value 9 • Try using ascii value 10 • Try using ascii value 111 • Try using ascii value 250

More Related